Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 143810aa21
Fetching contributors…

Cannot retrieve contributors at this time

65 lines (45 sloc) 1.651 kb

RSpec 2.x

spec_helper

require 'rack/test'

begin 
  require_relative '../my-app.rb'
rescue NameError
  require File.expand_path('../my-app.rb', __FILE__)
end

module RSpecMixin
  include Rack::Test::Methods
  def app() Sinatra::Application end
end

RSpec.configure { |c| c.include RSpecMixin }

If your app was defined using the modular style, use

def app() described_class end

instead of

def app() Sinatra::Application end

Shared Example Groups

Shared Example Groups

begin 
  require_relative 'spec_helper'
rescue NameError
  require File.expand_path('spec_helper', __FILE__)
end

shared_examples_for "my example app" do
  before(:each) do
    @expected = 'Frank'
  end
  it "should return a welcome greeting" do
    post '/', :name => @expected 
    last_response.body.should == "Hello #{@expected}!"
  end
end

describe "my session handler" do
  it_behaves_like "my example app"

  it "should return the name parameter from a session" do
    get '/session', {}, 'rack.session' => { 'name' => @expected }
    last_response.body.should == "Hello #{@expected}!" 
  end
end

RSpec 2.x Resources

Jump to Line
Something went wrong with that request. Please try again.