Using capybara for integration tests - Ramaze/ramaze GitHub Wiki
This has been sketched by @yorickpeterse in this gist It uses selenium driver, although you just can use other drivers
# Require Capybara stuff
require 'capybara'
require 'capybara/dsl'
Bacon.extend(Bacon::SpecDoxOutput)
# Setup capybara
Capybara.configure do |c|
# You can use alternate drivers here
c.default_driver = :selenium
c.app = Ramaze.middleware
# You might want to configure this is you want to save screenshots
c.save_and_open_page_path = File.join(Ramaze.options.roots.first, 'tmp/')
end
shared :capybara do
Ramaze.setup_dependencies
extend Capybara::DSL
end
# Just go as ususal
describe 'Testing Ramaze' do
behaves_like :capybara
# Ensure user can see home page
it 'Go to the homepage' do
visit '/'
page.has_content?('Inscriptions').should == true
end
# Ensure user can loging on web site
it 'Logs in' do
# First, create a User in our database so we can log in
User.create(:email=> '[email protected]', :password => 'xyz', :confirmed => true)
visit '/users/login'
fill_in 'Email', :with => '[email protected]'
fill_in 'Mot de passe', :with => 'xyz'
# Let's immortalize this memorable event
Capybara::Screenshot.screen_shot_and_save_page
# And try to log in
click_button 'connect'
# After log in, we should be on the profile page
page.current_path.should == '/profiles/index'
page.has_content?('Profile').should == true
end
end