Skip to content

Commit

Permalink
Added --strict switch
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jan 24, 2009
1 parent 365c7f3 commit a3f3bfa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion History.txt
Expand Up @@ -53,9 +53,9 @@ More blurb ideas
* TODO Autotest uses file:line instead of --scenario (current impl doesn't work on Windows)

=== New features
* TODO: --strict (Fail if there are missing or pending steps)
* TODO: Autoformatting (--autoformat -a)
* TODO: "Background" section
* New --strict option exits with an error code if there are undefined or pending steps.
* Filtering with --tags. If you put @various @tags on your features and scenarios, --tags lets you run a subset of them.
* Given, When, Then are automatically aliased to current language.
Ruby 1.8 doesn't allow non-ascii method names in the source, so unless you're on 1.9
Expand Down
16 changes: 16 additions & 0 deletions features/cucumber_cli.feature
Expand Up @@ -18,6 +18,22 @@ Feature: Cucumber command line
"""

Scenario: Fail with --strict
When I run cucumber -q features/sample.feature:5 --strict
Then it should fail with
"""
@one
Feature: Sample
@two @three
Scenario: Missing
Given missing
1 scenario
1 undefined step
"""

Scenario: Specify 2 line numbers where one is a tag
When I run cucumber -q features/sample.feature:5:14
Then it should fail with
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/extra_steps.rb
@@ -1,2 +1,2 @@
Given /^missing$/ do
end
end
10 changes: 8 additions & 2 deletions lib/cucumber/cli.rb
Expand Up @@ -41,6 +41,7 @@ def Kernel.flush
@error_stream = error_stream
@paths = []
@options = {
:strict => false,
:require => nil,
:lang => 'en',
:dry_run => false,
Expand Down Expand Up @@ -147,9 +148,12 @@ def parse_options!(args)
opts.on("-q", "--quiet", "Alias for --no-snippets --no-source.") do
@quiet = true
end
opts.on("-b", "--backtrace", "Show full backtrace for all errors") do
opts.on("-b", "--backtrace", "Show full backtrace for all errors.") do
Exception.cucumber_full_backtrace = true
end
opts.on("--strict", "Fail if there are any undefined or pending steps.") do
@options[:strict] = true
end
opts.on("-v", "--verbose", "Show the files and features loaded.") do
@options[:verbose] = true
end
Expand Down Expand Up @@ -184,7 +188,9 @@ def execute!(step_mother)
visitor = build_formatter_broadcaster(step_mother)
visitor.options = @options
visitor.visit_features(features)
Kernel.exit features.steps[:failed].length
exit_code = features.steps[:failed].length
exit_code += (features.steps[:undefined].length + features.steps[:pending].length) if @options[:strict]
Kernel.exit(exit_code)
end

private
Expand Down

0 comments on commit a3f3bfa

Please sign in to comment.