Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created February 28, 2011 20:41
Show Gist options
  • Save guilleiguaran/847989 to your computer and use it in GitHub Desktop.
Save guilleiguaran/847989 to your computer and use it in GitHub Desktop.
RSpec+Capybara acceptance test example
# acceptance/acceptance_helper.rb
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
# Put your acceptance spec helpers inside /spec/acceptance/support
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
# acceptance/support/database_cleaner.rb
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
# acceptance/support/helpers.rb
module HelperMethods
# Put helper methods you need to be available in all tests here.
def create_user
#User.create_with_omniauth(OmniAuth.config.mock_auth[:facebook])
user = Factory(:user)
return user
end
end
RSpec.configuration.include HelperMethods, :type => :acceptance
# acceptance/support/paths.rb
module NavigationHelpers
# Put helper methods related to the paths in your application here.
def homepage
"/"
end
def login_page
"/auth/facebook"
end
def logout_page
"/logout"
end
end
RSpec.configuration.include NavigationHelpers, :type => :acceptance
# acceptance/users_login_spec.rb
require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
feature "Users Login", %q{
In order to start using the page
As a potential user
I want to login using my Facebook account
} do
background do
end
scenario "I login in the page" do
visit login_page
page.should have_content('John')
page.should have_content('Logout')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment