Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent cucumber yml being read twice #416

Merged
merged 4 commits into from
Apr 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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