Fork me on GitHub

RSpec

RSpec is the main competitor to Test::Unit. It is feature rich and pleasant to read, but too heavy for some. Therefore most other frameworks mentioned here (except Minitest, Test::Unit and Cucumber) try to adopt its API without its inner complexity.

In your spec file or your spec helper, you can setup Rack::Test like this:

# spec/spec_helper.rb
require 'rack/test'
require 'rspec'

ENV['RACK_ENV'] = 'test'

require File.expand_path '../../my-app.rb', __FILE__

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

# For RSpec 2.x and 3.x
RSpec.configure { |c| c.include RSpecMixin }
# If you use RSpec 1.x you should use this instead:
Spec::Runner.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

Now use it in your specs

# spec/app_spec.rb
require File.expand_path '../spec_helper.rb', __FILE__

describe "My Sinatra Application" do
  it "should allow accessing the home page" do
    get '/'
    # Rspec 2.x
    expect(last_response).to be_ok

    # Rspec 1.x
    last_response.should be_ok
  end
end

RSpec 2.x Resources

RSpec 1.x Resources

Top