diff --git a/lib/cucumber/cli/options.rb b/lib/cucumber/cli/options.rb index b073c2cd8c..fdf4202080 100644 --- a/lib/cucumber/cli/options.rb +++ b/lib/cucumber/cli/options.rb @@ -62,6 +62,7 @@ def initialize(out_stream = STDOUT, error_stream = STDERR, options = {}) @profiles = [] @overridden_paths = [] @options = default_options + @profile_loader = options[:profile_loader] @options[:skip_profile_information] = options[:skip_profile_information] @quiet = @disable_profile_loading = nil @@ -350,15 +351,22 @@ 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) - ) + merge_with_profile(profile) end @options[:profiles] = @profiles 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? && diff --git a/spec/cucumber/cli/options_spec.rb b/spec/cucumber/cli/options_spec.rb index 84f672506a..1c5e6c1a51 100644 --- a/spec/cucumber/cli/options_spec.rb +++ b/spec/cucumber/cli/options_spec.rb @@ -208,6 +208,25 @@ def after_parsing(args) options[:formats].should == [['progress', output_stream], ['html', 'features.html']] end + 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 given_cucumber_yml_defined_as('foo' => '-q') options.parse!(%w[-p foo])