Skip to content

Commit

Permalink
Merge pull request #416 from cucumber/prevent_cucumber_yml_being_read…
Browse files Browse the repository at this point in the history
…_twice

Prevent cucumber yml being read twice

closes #217
  • Loading branch information
tooky committed Apr 5, 2013
2 parents 24496a2 + 897c32a commit 48a3c59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/cucumber/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? &&
Expand Down
19 changes: 19 additions & 0 deletions spec/cucumber/cli/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 48a3c59

Please sign in to comment.