[英]How to tell rspec to run without pending tests output?
Is there a way (maybe some key) to tell rspec to skip pending tests and don't print information about them? 有没有办法(可能是一些关键)告诉rspec跳过挂起的测试并且不打印有关它们的信息?
I have some auto generated tests like 我有一些自动生成的测试
pending "add some examples to (or delete) #{__FILE__}"
I run "bundle exec rspec spec/models --format documentation" and get somethin like this: 我运行“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)
......
I want to keep this files, cause I gonna change them later, but for now I want output like: 我想保留这些文件,因为我稍后会更改它们,但是现在我想输出如下:
Rating
allows to rate first time
disallow to rate book twice
Finished in 0.14011 seconds
10 examples, 0 failures, 8 pending
You could do something like this in your test file 您可以在测试文件中执行类似的操作
describe "the test I'm skipping for now" do
it "slow example", :skip => true do
#test here
end
end
and run your tests like this: 并像这样运行你的测试:
bundle exec rspec spec/models --format documentation --tag ~skip
where the ~
character excludes all tests with the following tag, in this case skip
其中
~
字符排除具有以下标记的所有测试,在本例中为skip
For posterity: you can suppress output of pending tests in the main body of documentation output by creating a custom formatter. 对于后代:您可以通过创建自定义格式化程序来抑制文档输出主体中待处理测试的输出。
(For RSpec 3). (对于RSpec 3)。 I made a house_formatter.rb file in my spec directory like this:
我在我的spec目录中创建了一个house_formatter.rb文件,如下所示:
class HouseFormatter < RSpec::Core::Formatters::DocumentationFormatter
RSpec::Core::Formatters.register self, :example_pending
def example_pending(notification); end
end
Then I added the following line to my .rspec file: 然后我将以下行添加到我的.rspec文件中:
--require spec/house_formatter
Now I can call the formatter with rspec --format HouseFormatter <file>
. 现在我可以使用
rspec --format HouseFormatter <file>
调用formatter。
Note that I still get the "pending tests" section at the end. 请注意,我仍然在最后得到“待定测试”部分。 But as far as I am concerned, that's perfect.
但就我而言,那是完美的。
This is the official "fix" posted for this problem on Github in response to the issue Marko raised, and as such it deserves a seperate answer. 这是Github针对此问题发布的官方“修复”,以回应Marko提出的问题 ,因此值得单独回答。
This is probably the better answer, too; 这也许是更好的答案; mine is pretty fragile.
我很脆弱。 Credit for this should go to Myron Marston on the Rspec team.
对此应归功于Rspec团队的Myron Marston 。
You can implement this for yourself pretty easily:
你可以很容易地为自己实现这个:
module FormatterOverrides def example_pending(_) end def dump_pending(_) end end RSpec::Core::Formatters::DocumentationFormatter.prepend FormatterOverrides
Or if you only want to silence block-less examples:
或者,如果你只想沉默无块的例子:
module FormatterOverrides def example_pending(notification) super if notification.example.metadata[:block] end def dump_pending(_) end end RSpec::Core::Formatters::DocumentationFormatter.prepend FormatterOverrides
Or, if you just want to filter out block-less pending examples (but still show other pending examples):
或者,如果您只想过滤掉无块的待处理示例(但仍显示其他待处理示例):
RSpec.configure do |c| c.filter_run_excluding :block => nil end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.