From 1c41e2714b2289f3eb78e27aece51172ff3087bd Mon Sep 17 00:00:00 2001 From: Joseph Wilk Date: Fri, 31 Oct 2008 09:58:00 +0000 Subject: [PATCH] Adding --no-snippets option to hide pending snippets when using pretty formatter --- History.txt | 1 + lib/cucumber/cli.rb | 4 ++++ lib/cucumber/formatters/pretty_formatter.rb | 2 +- spec/cucumber/cli_spec.rb | 8 ++++++++ .../formatters/pretty_formatter_spec.rb | 20 +++++++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/History.txt b/History.txt index 9c21ac6030..395901098d 100644 --- a/History.txt +++ b/History.txt @@ -23,6 +23,7 @@ in the inside string. If the triple quotes are indented 4 spaces, then the text spaces removed too. === New features +* Added --no-snippets option to hide snippets for pending steps when using Pretty formatter (#69 Joseph Wilk) * Added Autotest support - work in progress... (Peter Jaros) * Added new --exclude option (Bryan Helkamp) * Added new --scenario option (Peter Jaros) diff --git a/lib/cucumber/cli.rb b/lib/cucumber/cli.rb index afe0753639..34a6505e0d 100644 --- a/lib/cucumber/cli.rb +++ b/lib/cucumber/cli.rb @@ -33,6 +33,7 @@ def initialize :lang => 'en', :dry_run => false, :source => true, + :snippets => true, :formats => {}, :excludes => [], :scenario_names => nil @@ -101,6 +102,9 @@ def parse_options!(args) opts.on("-n", "--no-source", "Don't show the file and line of the step definition with the steps.") do @options[:source] = false end + opts.on("-s", "--no-snippets", "Don't show the snippets for pending steps") do + @options[:snippets] = false + end opts.on_tail("--version", "Show version") do puts VERSION::STRING exit diff --git a/lib/cucumber/formatters/pretty_formatter.rb b/lib/cucumber/formatters/pretty_formatter.rb index 09069aecd2..555711a651 100644 --- a/lib/cucumber/formatters/pretty_formatter.rb +++ b/lib/cucumber/formatters/pretty_formatter.rb @@ -158,7 +158,7 @@ def dump @io.print reset - print_snippets + print_snippets if @options[:snippets] end def print_snippets diff --git a/spec/cucumber/cli_spec.rb b/spec/cucumber/cli_spec.rb index 428f2a5717..3a338d9b89 100644 --- a/spec/cucumber/cli_spec.rb +++ b/spec/cucumber/cli_spec.rb @@ -25,6 +25,7 @@ def mock_broadcaster(stubs = {}) :dry_run => false, :lang => 'en', :source => true, + :snippets => true, :excludes => [], :scenario_names => nil } @@ -43,6 +44,7 @@ def mock_broadcaster(stubs = {}) :dry_run => false, :lang => 'en', :source => true, + :snippets => true, :excludes => [], :scenario_names => nil } @@ -55,6 +57,12 @@ def mock_broadcaster(stubs = {}) cli.options[:source].should be_false end + it "should accept --no-snippets option" do + cli = CLI.new + cli.parse_options!(%w{--no-snippets}) + cli.options[:snippets].should be_false + end + it "should accept --out option" do cli = CLI.new File.should_receive(:open).with('jalla.txt', 'w') diff --git a/spec/cucumber/formatters/pretty_formatter_spec.rb b/spec/cucumber/formatters/pretty_formatter_spec.rb index bd9c6063e7..8d6277fdc3 100644 --- a/spec/cucumber/formatters/pretty_formatter_spec.rb +++ b/spec/cucumber/formatters/pretty_formatter_spec.rb @@ -10,6 +10,9 @@ def mock_step(stubs={}) :format => 'formatted yes', :name => 'example', :error => nil, + :padding_length => 2, + :file => 'test', + :line => 1, :row? => false}.merge(stubs)) end @@ -78,6 +81,23 @@ def mock_proc io.string.should =~ /\n\n Scenario: spacey/ end + {'should' => true, 'should not' => false}.each do |should_or_should_not, show_snippet| + describe "snippets option #{show_snippet}" do + + it "#{should_or_should_not} show snippet for pending step" do + @io = StringIO.new + step_mother = mock('step_mother') + @formatter = PrettyFormatter.new @io, step_mother, :snippets => show_snippet + + @formatter.step_pending(mock_step(:actual_keyword => 'Given', :name => 'pending step snippet'), nil, nil) + @formatter.dump + + @io.string.send(should_or_should_not.gsub(' ','_').to_sym, include("Given /^pending step snippet$/ do")) + end + + end + end + describe "show source option true" do before(:each) do