-
-
Notifications
You must be signed in to change notification settings - Fork 753
Add --fail-no-examples option: fail if no RSpec examples #2302
Conversation
Was there a regression in our rake task? If so, it'd be good for us to know about it so we can fix it. Anyhow, if we're going to add this, I think it would be better to add it to # spec/spec_helper.rb
RSpec.configure do |c|
if ENV['CI']
c.fail_if_no_examples = true
end
end
(The latter is necessary to ensure Thoughts? |
Yes, you are right, I want to set this option permanently and setting it by As it comes for rake task potential regression, I opened an issue: #2303 . |
@@ -199,6 +199,10 @@ def only_failures_but_not_configured? | |||
# The exit code to return if there are any failures (default: 1). | |||
add_setting :failure_exit_code | |||
|
|||
# @macro add_setting | |||
# Whether or not to fail when there are no RSpec examples (default: false). | |||
add_setting :fail_no_examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the build is failing due to a drop in test coverage, I believe this needs a test covering it to fix that :)
e68d17f
to
322dec2
Compare
I've just rebased this PR. The option is named: And thanks for that comment on |
@@ -110,6 +110,9 @@ def setup(err, out) | |||
def run_specs(example_groups) | |||
@configuration.reporter.report(@world.example_count(example_groups)) do |reporter| | |||
@configuration.with_suite_hooks do | |||
if @world.example_count(example_groups) == 0 && @configuration.fail_if_no_examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@world.example_count(example_groups)
is being called above on line 111 and then again here on line 113. Instead of calling it twice, can you call it once, store the value in a local variable, and then use it in two places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course! I was experimenting here and forgot.
I updated the PR with your remarks. Edit: The low level tests are now in: |
@@ -0,0 +1,46 @@ | |||
Feature: fail if no examples | |||
|
|||
Use the `fail_if_no_examples` option to make RSpec exit with exit status 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically RSpec will exit with the configured error failure status, so prehaps this should read:
to make RSpec exit with a failure status (by default 1)
which also avoids the double exit :)
@xmik this is looking really close and is very well done! |
Thanks @myronmarston and @JonRowe for all the remarks. I incorporated them. It's nice to see that you care for RSpec and keep the code clean. Let me know if you want me to squash commits or correct something else. |
@@ -0,0 +1,31 @@ | |||
Feature: fail if no examples | |||
|
|||
Use the `fail_if_no_examples` option to make RSpec exit with a failure status (by default 1) if there are 0 examples. Using this option, it is recommended to add a `--require spec_helper` option to `.rspec` file to ensure the `fail_if_no_examples` option is set even if no spec files are loaded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: s/if there are 0 examples/if there are no examples/.
I think it reads more naturally and aligns with the config option name.
Please do squash it, then I'll gladly merge it :). |
Exit with a failure status if no RSpec examples. Default behavior not changed. CLI option not implemented.
6c9e8d8
to
fea5c47
Compare
|
Thanks @xmik |
* Add fail_if_no_examples option: exit 1 if no RSpec examples, Default behavior not changed. CLI option not implemented. * Add fail_if_no_examples option: better tests * Add fail_if_no_examples option: support custom failure_exit_code and correct cucumber test to be better rendered on relish
[ci skip]
I added a new command line option:
--fail-no-examples
. It defaults to false, so default behavior is not changed. But, if this option is set and there are no RSpec examples to be run, exit status will be 1 (so far it was always 0).Motivation
We use RSpec rake task on CI. Having updated RSpec from 3.3.0 to 3.5.0, there was some change in that rake task code. Without changing anything, the rake task resulted in running 0 examples and exit status was 0. Jobs were passed on CI, but I'd prefer if they were not.