mwlang
unread,Nov 19, 2009, 12:51:33 AM11/19/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ramaze
I am trying to learn to write bacon scripts for automated testing of
my controllers. My controllers and views all work just fine and
render in the browser.
However, for some reason, when I attempt to test my controller actions
with Bacon, the Rack::MockResponse's @body is always empty and Content-
Length is always "0"
This is my test script:
require File.join('..', 'spec_helper')
describe Login do
behaves_like :rack_test
should 'show login page' do
get('/login').status.should == 200
last_response['Content-Type'].should == 'text/html'
last_response.should =~ /Login/
end
should 'show login page' do
post('/login').status.should == 200
last_response['Content-Type'].should == 'text/html'
last_response.should =~ /Login/
end
should 'turn caching off via headers' do
get('/login').status.should == 200
last_response.headers['Pragma'].should == 'no-cache'
Time.parse(last_response.headers['Expires']).should < Time.now
last_response.headers['Cache-Control'].should == 'no-store'
end
end
This is the result:
12:45:39:controllers >> bacon login.rb
I [2009-11-19 00:45:43 $66970] INFO | : activating sequel
I [2009-11-19 00:45:43 $66970] INFO | : activating i18n
Login
- should show login page [FAILED]
- should show login page [FAILED]
- should turn caching off via headers
Bacon::Error: #<Rack::MockResponse:0x19a4f9c @headers={"Content-
Type"=>"text/html", "Content-Length"=>"0", "Pragma"=>"no-cache",
"Expires"=>"Tue, 18 Nov 2008 18:45:43 -0500", "Cache-Control"=>"no-
store"}, @errors="", @original_headers={"Content-Type"=>"text/html",
"Pragma"=>"no-cache", "Content-Length"=>"0", "Cache-Control"=>"no-
store", "Expires"=>"Tue, 18 Nov 2008 18:45:43 -0500"}, @status=200,
@body="">.=~(/Login/) failed
./login.rb:9: Login - should show login page
./login.rb:6
./login.rb:3
Bacon::Error: #<Rack::MockResponse:0x199d8f0 @headers={"Content-
Type"=>"text/html", "Content-Length"=>"0", "Pragma"=>"no-cache",
"Expires"=>"Tue, 18 Nov 2008 18:45:43 -0500", "Cache-Control"=>"no-
store"}, @errors="", @original_headers={"Content-Type"=>"text/html",
"Pragma"=>"no-cache", "Content-Length"=>"0", "Cache-Control"=>"no-
store", "Expires"=>"Tue, 18 Nov 2008 18:45:43 -0500"}, @status=200,
@body="">.=~(/Login/) failed
./login.rb:15: Login - should show login page
./login.rb:12
./login.rb:3
3 specifications (10 requirements), 2 failures, 0 errors