From 298169e3a35010431e2d9f567deeac3aa6fb09fc Mon Sep 17 00:00:00 2001 From: Steve Tooke Date: Sun, 31 Mar 2013 21:27:38 +0100 Subject: [PATCH 1/3] Reuse the same profile loader for merged options --- lib/cucumber/cli/options.rb | 5 ++++- spec/cucumber/cli/options_spec.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/cucumber/cli/options.rb b/lib/cucumber/cli/options.rb index f591982738..2a19ec4a65 100644 --- a/lib/cucumber/cli/options.rb +++ b/lib/cucumber/cli/options.rb @@ -63,6 +63,7 @@ def initialize(out_stream = STDOUT, error_stream = STDERR, options = {}) @profiles = [] @overridden_paths = [] @options = default_options + @profile_loader = options[:profile_loader] @quiet = @disable_profile_loading = nil end @@ -353,7 +354,9 @@ def merge_profiles @profiles.each do |profile| profile_args = profile_loader.args_from(profile) reverse_merge( - Options.parse(profile_args, @out_stream, @error_stream, :skip_profile_information => true) + Options.parse(profile_args, @out_stream, @error_stream, + :skip_profile_information => true, + :profile_loader => profile_loader) ) end end diff --git a/spec/cucumber/cli/options_spec.rb b/spec/cucumber/cli/options_spec.rb index 8669bcdcaf..a5b381e283 100644 --- a/spec/cucumber/cli/options_spec.rb +++ b/spec/cucumber/cli/options_spec.rb @@ -227,6 +227,18 @@ def after_parsing(args) options[:formats].should == [['progress', output_stream], ['html', 'features.html']] end + it "only parses cucumber.yml once" do + $parse_count = 0 + given_cucumber_yml_defined_as(<<-END + <% $parse_count += 1 %> + default: --format pretty + END + ) + options = Options.new(output_stream, error_stream, :default_profile => 'default') + options.parse!(%w(-f progress)) + $parse_count.should == 1 + end + it "respects --quiet when defined in the profile" do given_cucumber_yml_defined_as('foo' => '-q') options.parse!(%w[-p foo]) From b4acf425e913354cde13efe80876a638f7ec7de3 Mon Sep 17 00:00:00 2001 From: Steve Tooke Date: Mon, 1 Apr 2013 20:43:16 +0100 Subject: [PATCH 2/3] Extract merge_with_profile method --- lib/cucumber/cli/options.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/cucumber/cli/options.rb b/lib/cucumber/cli/options.rb index 2a19ec4a65..5fb7322d49 100644 --- a/lib/cucumber/cli/options.rb +++ b/lib/cucumber/cli/options.rb @@ -352,15 +352,20 @@ def merge_profiles @profiles << @default_profile if default_profile_should_be_used? @profiles.each do |profile| - profile_args = profile_loader.args_from(profile) - reverse_merge( - Options.parse(profile_args, @out_stream, @error_stream, - :skip_profile_information => true, - :profile_loader => profile_loader) - ) + merge_with_profile(profile) end end + def merge_with_profile(profile) + profile_args = profile_loader.args_from(profile) + profile_options = Options.parse( + profile_args, @out_stream, @error_stream, + :skip_profile_information => true, + :profile_loader => profile_loader + ) + reverse_merge(profile_options) + end + def default_profile_should_be_used? @profiles.empty? && profile_loader.cucumber_yml_defined? && From d62ba6a1ee2b44b35796e064db9009be588415d1 Mon Sep 17 00:00:00 2001 From: Steve Tooke Date: Wed, 3 Apr 2013 12:42:31 +0100 Subject: [PATCH 3/3] Try not to stomp on global variables. --- spec/cucumber/cli/options_spec.rb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/spec/cucumber/cli/options_spec.rb b/spec/cucumber/cli/options_spec.rb index a5b381e283..d042b39ee2 100644 --- a/spec/cucumber/cli/options_spec.rb +++ b/spec/cucumber/cli/options_spec.rb @@ -227,16 +227,23 @@ def after_parsing(args) options[:formats].should == [['progress', output_stream], ['html', 'features.html']] end - it "only parses cucumber.yml once" do - $parse_count = 0 - given_cucumber_yml_defined_as(<<-END - <% $parse_count += 1 %> - default: --format pretty - END - ) - options = Options.new(output_stream, error_stream, :default_profile => 'default') - options.parse!(%w(-f progress)) - $parse_count.should == 1 + it "only reads cucumber.yml once" do + original_parse_count = $cucumber_yml_read_count + $cucumber_yml_read_count = 0 + + begin + given_cucumber_yml_defined_as(<<-END + <% $cucumber_yml_read_count += 1 %> + default: --format pretty + END + ) + options = Options.new(output_stream, error_stream, :default_profile => 'default') + options.parse!(%w(-f progress)) + + $cucumber_yml_read_count.should == 1 + ensure + $cucumber_yml_read_count = original_parse_count + end end it "respects --quiet when defined in the profile" do