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

exec_in_context loops should ensure the application context always switches back after the loop is finished. #21

Open
pythonesque opened this issue Oct 14, 2011 · 0 comments

Comments

@pythonesque
Copy link

If some Rspec fails (or anything else for that matter), exec_in_context doesn't reset the application context properly, and large numbers of tests afterwards start to fail.

Fix is basically to wrap the code in ensure blocks.

In Lebowski::Foundation::Support::ApplicationContextManager

  def exec_in_context(app, app_name=nil, &block)
    previous_app_context = @current_application_context.clone
    switch_application_context_to app, app_name
    yield app
  ensure
    switch_application_context_to previous_app_context[:app], previous_app_context[:app_name]
  end

  def exec_driver_in_context(app, &block)
    previous_app_context = nil
    if not has_current_application_context?(app)
      previous_app_context = @current_application_context.clone
      switch_application_context_to app
    end

    yield @driver

  ensure
    if not previous_app_context.nil?
      switch_application_context_to previous_app_context[:app], previous_app_context[:app_name]
  end

There are more elegant ways of doing it probably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant