[rspec-users] How to use RSpec 2 with Sinatra 1.0

Maurizio De Santis desantis.maurizio at gmail.com
Sun Sep 19 05:38:22 EDT 2010


I am trying to use RSpec 2 with a Sinatra 1.0 application, but I have
no idea about whether they are compatible or not. I tried this:

in $SINATRA_APP_ROOT/app.rb:

require 'sinatra'

set :app_file, __FILE__
set :root, File.dirname(__FILE__)
set :config_path, File.join(Sinatra::Application.root, 'config')

require File.join(Sinatra::Application.config_path, 'config.rb')

# Workaround to fix an issue between Sinatra 1.0 and ruby 1.9.2
# Skipped when app is not launched directly
enable :run if $0.eql?(__FILE__)

get '/' do
  haml :index

in $SINATRA_APP_ROOT/spec_helper.rb:

require 'db_web_console'
require 'rack/test'

in $SINATRA_APP_ROOT/sinatra_app/sinatra_app_spec.rb:

require 'spec_helper'

def app
  @app ||= Sinatra::Application

describe 'Sinatra App' do

  include Rack::Test::Methods

  it "says Hello" do
    get '/'
    last_response.should be_ok
    last_response.body.should == 'Hello!'

But trying

rspec spec/

, I get this error:

  1) Sinatra App says ciao
     Failure/Error: @app ||= Sinatra::Application
     uninitialized constant
     # ./spec/db_web_console/db_web_console_spec.rb:4:in `app'
     # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/
test/methods.rb:31:in `build_rack_mock_session'
     # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/
test/methods.rb:27:in `rack_mock_session'
     # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/
test/methods.rb:42:in `build_rack_test_session'
     # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/
test/methods.rb:38:in `rack_test_session'
     # $HOME/.rvm/gems/ruby-1.9.2-p0/gems/rack-test-0.5.4/lib/rack/
test/methods.rb:46:in `current_session'
     # ./spec/db_web_console/db_web_console_spec.rb:14:in `block (2
levels) in '

I tried in other ways, but without success... can someone figure out
what can be the problem?

More information about the rspec-users mailing list