Reputation: 279
Is there a way (maybe some key) to tell rspec to skip pending tests and don't print information about them?
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:
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
Upvotes: 16
Views: 6078
Reputation: 45943
The best solution I have found for entire files is to change the name of the file:
foo_spec_skipped.rb
Upvotes: 0
Reputation: 1104
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.
This is probably the better answer, too; mine is pretty fragile. Credit for this should go to Myron Marston on the Rspec team.
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
Upvotes: 6
Reputation: 1104
For posterity: you can suppress output of pending tests in the main body of documentation output by creating a custom formatter.
(For RSpec 3). I made a house_formatter.rb file in my spec directory like this:
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:
--require spec/house_formatter
Now I can call the formatter with rspec --format HouseFormatter <file>
.
Note that I still get the "pending tests" section at the end. But as far as I am concerned, that's perfect.
Upvotes: 7
Reputation: 10997
Take a look at tags -
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
Upvotes: 11