Testing Rack::Flash in Sinatra

Here’s a slightly dumb way to test Rack::Flash in a Sinatra app…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require File.dirname(__FILE__) + '/../test_helper.rb'
 
module FundAStache
  class Application
    get '/rack_flash_test' do
      flash[:notice]='rack flash is working'
      haml :index
    end
  end
end
 
class FundastacheTest < Test::Unit::TestCase
  include Rack::Test::Methods
 
  def flash
    last_request.env['x-rack.flash']
  end
 
  def app
    @app ||= FundAStache::Application
  end
 
  def test_rack_flash_working
    # see fake route above...
    get '/rack_flash_test'
    assert_not_nil flash
    assert last_response.body.include?("rack flash is working")
  end
end
Posted: March 8th, 2010 | Author: admin | Filed under: Code | Tags: , , , , | 1 Comment »

One Comment on “Testing Rack::Flash in Sinatra”

  1. 1 John Wilkinson said at 3:37 pm on November 10th, 2010:

    If slightly dumb = hella smart, then yes ^_^ awesome


Leave a Reply