Skip to content

Cacheable Flash 0.1.4 — Test Helpers

Brian Takita
Authors:Brian Takita
Posted on:October 8, 2007

Cacheable Flash testing

Repost from https://tanzu.vmware.com/content/blog/cacheable-flash-0-1-4-test-helpers

I just released Cacheable Flash 0.1.4. This version includes test helpers so you can easily test your cache messages. It works by allowing you to make assertions on the flash cookie.

Here is a test/unit example:

require "cacheable_flash/test_helpers"

class TestController < ActionController::Base
    def index
        flash["notice"] = "In index"
    end
end

class ControllerTest < Test::Unit::TestCase
    include CacheableFlash::TestHelpers

    def setup
        @controller = TestController.new
        @request = ActionController::TestRequest.new
        @response = ActionController::TestResponse.new
    end

    def test_cacheable_flash_action
        get :index
        asset_equal "In index", flash_cookie["notice"]
    end
end

Here is a rspec example:

require "cacheable_flash/test_helpers"

class TestController < ActionController::Base
    def index
        flash["notice"] = "In index"
    end
end

describe TestController, "#index" do
    include CacheableFlash::TestHelpers

    it "writes to the flash cookie" do
        get :index
        flash_cookie["notice"].should == "In index"
    end
end

You can install Cacheable Flash by running:

ruby script/plugin install svn://rubyforge.org/var/svn/pivotalrb/cacheable_flash/trunk

See the Cacheable Flash blog post, Show Flash Messages on Cached Pages, and the README for more information.