Skip to content
djanowski edited this page Sep 12, 2010 · 8 revisions

If you are finding issues when testing sessions, make sure you don’t use this:

enable :sessions

Call the Rack middleware directly (you’ll be able to set additional options, too):

use Rack::Session::Cookie

Classic style

App


require "sinatra"

get "/" do
  "Hello World"
end

Test


  require "rack/test"
  require "webrat"
  require "test/unit"

  Webrat.configure do |config|
    config.mode = :rack
  end

  class AppTest < Test::Unit::TestCase
    include Rack::Test::Methods
    include Webrat::Methods
    include Webrat::Matchers

    def app
      Sinatra::Application.new
    end

    def test_it_works
      visit "/"
      assert_contain("Hello world")
    end
  end

Modular style

App


class App < Sinatra::Default
  get "/" do
    "Hello World"
  end
end

Test


  require "rack/test"
  require "webrat"
  require "test/unit"

  Webrat.configure do |config|
    config.mode = :rack
  end

  class AppTest < Test::Unit::TestCase
    include Rack::Test::Methods
    include Webrat::Methods
    include Webrat::Matchers

    def app
      App.new
    end

    def test_it_works
      visit "/"
      assert_contain("Hello world")
    end
  end

Clone this wiki locally