Skip to content

Instantly share code, notes, and snippets.

@rdamen
Forked from nakajima/README
Created August 4, 2009 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdamen/161488 to your computer and use it in GitHub Desktop.
Save rdamen/161488 to your computer and use it in GitHub Desktop.
(in /home/ron/161488)
Test
- no flash
- default environment is development
- flash in default environment
- flash in production environment
- flash in test environment (FAILED - 1)
1)
Rack::Flash::SessionUnavailable in 'Test flash in test environment'
Rack::Flash depends on session middleware.
(eval):3:in `get'
/home/ron/161488/rack-flash spec.rb:40:in `block (2 levels) in <top (required)>'
Finished in 0.062986788 seconds
5 examples, 1 failure
require 'sinatra'
require 'rack-flash'
use Rack::Flash
enable :sessions
get '/' do
flash[:message] || 'No flash'
end
get '/set' do
flash[:message] = 'Hello!'
'Flash message set!'
end
require 'rubygems'
require 'spec'
require 'spec/interop/test'
require 'rack/test'
require 'rack-flash example.rb'
Spec::Runner.configure { |c| c.include Rack::Test::Methods }
def app
Sinatra::Application.new
end
describe 'Test' do
specify 'no flash' do
get '/'
last_response.body.should == 'No flash'
end
specify 'default environment is development' do
Sinatra::Base.environment.should eql :development
end
specify 'flash in default environment' do
get '/set'
get '/'
last_response.body.should == 'Hello!'
end
specify 'flash in production environment' do
Sinatra::Base.set :environment, :production
get '/set'
get '/'
last_response.body.should == 'Hello!'
end
specify 'flash in test environment' do
Sinatra::Base.set :environment, :test
get '/set'
get '/'
last_response.body.should == 'Hello!'
end
end
require 'spec/rake/spectask'
task :default => :spec
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_files = FileList['*spec.rb']
t.spec_opts = ['-cfs']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment