-
Notifications
You must be signed in to change notification settings - Fork 37
Bacon
- Setting POST params in bacon tests
- Following redirects
- Running a single test, and not the whole suite
- Making bacon more quiet
- Mocking authentication will let you pretend a user is logged in for your tests
This is probably because your controller issues a redirect_referer
but the referer isn't set. so you end up on the '/' page.
You can force the referer in the POST request, passing a env hash as the third argument :
post('/album/save', { :artist => 12 }, { 'HTTP_REFERER' => '/album/create' }
This is probably because your helpers are not loaded first in your app.rb top file. Change it so the helpers are required first :
require __DIR__('helper/init')
require __DIR__('model/init')
require __DIR__('controller/init')
behaves_like
basically tells bacon to use a certain configuration for the
describe() block and let you use #get, #post, ... methods.
For instance, when a user creates a must-be-unique-record that already exists, should I return a 406 , Or a 200 ?
When writing REST service, you probably want to use 4xx codes. But If you write a web application, just return a 200 and explain why it failed.
You can use flash[:error]
for this.
The behaves_like :rack_test
is very convenient for testing your application behavior, but it doesn't test with your config.ru
file which can be a problem if your application uses another Rack application for specific url using the map method :
map "/user" do
# This is a Grape application
run UserApi
end
Ramaze.start...
So instead of doing this in your test :
require_relative '../helper'
describe UserApi do
behaves_like :rack_test
should...
end
You'll have to specify which Rack Application (created by RackBuilder
) to use by overriding Rack::Test.app
method :
require_relative '../helper'
describe UserApi do
extend Rack::Test::Methods
def app
Rack::Builder.parse_file("config.ru").first
end
should...
end
Hope this helps :)
- Website
- Google Groups
- User Guide
- [#ramaze on the Freenode network] (http://webchat.freenode.net/?channels=ramaze)