Plugins - Flashback

StarAdd to favorites

Calling flashback in your functional test sometime after the TestRequest is instantiated and before your first call to an action, will allow you to access the discarded flash variables (those that were flashed) during the request processing. Specifically, it will allow you to access the Flash.now variables by name.

You will access these discarded variables similar to how you would access them in Flash.now, but this time via a flashed method. For example:

  class FooController < ApplicationController
    def create
      ...
      flash.now[:error] = 'Whoops!' unless params[:foo][:baz]
      ...
    end
  end

  class FooControllerTest < ActionController::TestCase
    def test_create_should_set_some_flash_now_variable
      flashback
      get :create, :foo => {:bar => 'hello'}
      assert_equal 'Whoops!', flash.flashed[:error]
    end
  end

What you will not have access to via flashed are the normal, inter-request Flash variables. This is because Flashback is only tracking those flash variables that are discarded during the transaction, which includes all variables passed through Flash.now.

If you want flashed available all of the time, then simply call flashback in the setup method of your TestCase. There are likely better ways that I hope someone will tell me about, but I just wanted to get this plugin out-the-door.

The only caveat to Flashback is that if you define your own Flash instance and pass that to your various process methods (get, post, head, etc.), your flash will override Flashback’s, rendering it useless.

Justin Knowlden

http://glomp.rubyforge.org/flashback/

http://glomp.rubyforge.org/svn/plugins/flashback

Rails' (MIT)

  • Currently 5.0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Testing

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?