FrozenCanuck / Lebowski

The test automation framework for SproutCore applications
http://frozencanuck.wordpress.com
MIT License
78 stars 8 forks source link

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

Open pythonesque opened 13 years ago

pythonesque commented 13 years ago

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.