Skip to content

Instantly share code, notes, and snippets.

@joshuaclayton
Created October 6, 2012 04:02
Show Gist options
  • Save joshuaclayton/cd39b0a38d077ff36883 to your computer and use it in GitHub Desktop.
Save joshuaclayton/cd39b0a38d077ff36883 to your computer and use it in GitHub Desktop.
# spec/support/integration.rb
RSpec.configure do |config|
config.include Integration::SignInHelpers, only: :integration
config.include Integration::NoticeHelpers, only: :integration
end
# spec/support/integration/notice_helpers.rb
module Integration
module NoticeHelpers
def user_sees_notice(text)
expect(page).to have_css '.flash.notice', text: text
end
end
end
# spec/support/integration/sign_in_helpers.rb
module Integration
module SignInHelpers
def sign_in_with(email, password)
visit sign_in_path
fill_in 'Email', with: email
fill_in 'Password', with: password
click_button 'Sign In'
end
end
end
# spec/integration/sign_in_spec.rb
feature 'Signing in' do
background do
create :user, email: 'person@example.com', password: 'password'
end
scenario 'signs the user in successfully with a valid email and password' do
sign_in_with 'person@example.com', 'password'
user_sees_welcome_message 'Welcome, person@example.com'
end
scenario 'notifies the user if his email or password is invalid' do
sign_in_with user.email, 'wrong password'
user_sees_notice 'Invalid email or password'
end
def user_sees_welcome_message(text)
expect(page).to have_css 'nav .greeting', text: text
end
end
@martinstreicher
Copy link

Are drivers other than Capybara compatible with RSpec?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment