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

Conversation

tooky
Copy link
Member

@tooky tooky commented Apr 1, 2013

This fixes #217.

We were rereading cucumber.yml for every profile we were merging in because we were creating a new profile_loader each time we were parsing options.

I've used a global variable and erb to test how many times the cucumber.yml is parsed: https://github.com/cucumber/cucumber/compare/prevent_cucumber_yml_being_read_twice#L1R231

Does anyone have a better idea?

@mattwynne
Copy link
Member

Nice one @tooky!

I don't mind the global variable too much, but leaving it behind does niggle, doesn't it?

Other ideas:

  1. Print to the output stream in the ERB and then check the output only appears once.
  2. Define a module with an attr_accessor, increment that in the ERB, then undefine the constant at the end of the example.

@tooky
Copy link
Member Author

tooky commented Apr 3, 2013

Well none of them feel great @mattwynne.

I wasn't able to output to the output stream, just STDOUT.

This just seems ugly.

it "only parses cucumber.yml once" do
  ::ParseCounter = Class.new do
    attr_accessor :count
  end.new

  ParseCounter.count = 0

  given_cucumber_yml_defined_as(<<-END
  <% ParseCounter.count += 1 %>
  default: --format pretty
  END
  )
  options = Options.new(output_stream, error_stream, :default_profile => 'default')
  options.parse!(%w(-f progress))

  ParseCounter.count.should == 1

  Object.send(:remove_const, :ParseCounter)
end

I think, I'll reset the $global_variable to whatever it was before the test - which should be nil.

it "only parses cucumber.yml once" do
  original_parse_count = $parse_count
  $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
  $parse_count = original_parse_count
end

@os97673
Copy link
Member

os97673 commented Apr 3, 2013

@tooky I think you should reset the variable in ensure block, to have it restored even if some exception has been thrown.

@tooky
Copy link
Member Author

tooky commented Apr 3, 2013

@os97673 - good point, thanks!

…l_being_read_twice

Conflicts:
	lib/cucumber/cli/options.rb
tooky added a commit that referenced this pull request Apr 5, 2013
…_twice

Prevent cucumber yml being read twice

closes #217
@tooky tooky merged commit 48a3c59 into master Apr 5, 2013
@tooky tooky deleted the prevent_cucumber_yml_being_read_twice branch April 5, 2013 15:26
@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cucumber.yml is loaded/parsed twice
3 participants