如何判断rspec在没有挂起测试输出的情况下运行?
有没有办法(可能是一些关键)告诉rspec跳过挂起的测试并且不打印有关它们的信息?
我有一些自动生成的测试
pending "add some examples to (or delete) #{__FILE__}"
我运行“bundle exec rspec spec / models –format documentation”并得到这样的东西:
Rating allows to rate first time disallow to rate book twice Customer add some examples to (or delete) /home/richelieu/Code/first_model/spec/models/customer_spec.rb (PENDING: No reason given) Category add some examples to (or delete) /home/richelieu/Code/first_model/spec/models/category_spec.rb (PENDING: No reason given) ......
我想保留这些文件,因为我稍后会更改它们,但是现在我想输出如下:
Rating allows to rate first time disallow to rate book twice Finished in 0.14011 seconds 10 examples, 0 failures, 8 pending
看看标签 –
您可以在测试文件中执行类似的操作
describe "the test I'm skipping for now" do it "slow example", :skip => true do #test here end end
并像这样运行你的测试:
bundle exec rspec spec/models --format documentation --tag ~skip
其中~
字符排除具有以下标记的所有测试,在本例中为skip
对于后代:您可以通过创建自定义格式化程序来抑制文档输出主体中待处理测试的输出。
(对于RSpec 3)。 我在我的spec目录中创建了一个house_formatter.rb文件,如下所示:
class HouseFormatter < RSpec::Core::Formatters::DocumentationFormatter RSpec::Core::Formatters.register self, :example_pending def example_pending(notification); end end
然后我将以下行添加到我的.rspec文件中:
--require spec/house_formatter
现在我可以使用rspec --format HouseFormatter
调用formatter。
请注意,我仍然在最后得到“待定测试”部分。 但就我而言,这是完美的。
这是Github针对此问题发布的官方“修复”,以回应Marko提出的问题 ,因此它应该得到一个单独的答案。
这也许是更好的答案; 我很脆弱。 对此应归功于Rspec团队的Myron Marston 。
你可以很容易地为自己实现这个:
module FormatterOverrides def example_pending(_) end def dump_pending(_) end end RSpec::Core::Formatters::DocumentationFormatter.prepend FormatterOverrides
或者,如果你只想沉默无块的例子:
module FormatterOverrides def example_pending(notification) super if notification.example.metadata[:block] end def dump_pending(_) end end RSpec::Core::Formatters::DocumentationFormatter.prepend FormatterOverrides
或者,如果您只想过滤掉无块的待处理示例(但仍显示其他待处理示例):
RSpec.configure do |c| c.filter_run_excluding :block => nil end