Created
August 12, 2011 00:13
-
-
Save IdahoEv/1141135 to your computer and use it in GitHub Desktop.
Full-stack integration testing without Cucumber: using the RSpec-Steps/Capybara/Selenium stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## spec/support/browser-integration.rb | |
## This is just some useful tools we use to help in writing integration specs. | |
require 'capybara/rspec' | |
require 'selenium-webdriver' | |
require 'rspec-steps' | |
Capybara.register_driver(:selenium_chrome) do |app| | |
Capybara::Selenium::Driver.new(app, :browser => :chrome) | |
end | |
Capybara.default_driver = :selenium | |
module SaveAndOpenOnFail | |
def instance_eval(&block) | |
super(&block) | |
rescue Object => ex | |
wrapper = ex.exception("#{ex.message}\nLast view at: file://#{save_page}") | |
wrapper.set_backtrace(ex.backtrace) | |
raise wrapper | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group :development, :test do | |
gem 'rspec' | |
gem 'rspec-rails' | |
gem 'factory_girl_rails' | |
gem 'ruby-debug' | |
gem 'capybara' | |
gem 'launchy' | |
gem 'thin' | |
gem 'database_cleaner' | |
gem 'rspec-steps' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## spec/integration/login_and_change_password_spec.rb | |
steps "Login and change password", :type => :request do | |
before do | |
Factory( | |
:user, | |
:name => "Johnny User", | |
:password => 'password', | |
:password_confirmation => 'password' | |
) | |
end | |
it "should show the login form" do | |
visit root | |
page.should have_text "Login" | |
end | |
it "should successfully log in" do | |
fill_in :name, "Johnny User" | |
click "Login" | |
page.should have_text "Welcome, Johnny!" | |
end | |
it "should load the password change form" do | |
click "My Settings" | |
click "Update Password" | |
page.should have_selector("form#update_password") | |
end | |
it "should change the user's password successfully" do | |
fill_in :password, "foobar" | |
fill_in :password_confirmation, "foobar" | |
click "Change Password" | |
page.should have_text "Password changed successfully!" | |
User.find_by_name("Johnny User").valid_password?("foobar").should be_true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## spec/spec_helper.rb | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
config.backtrace_clean_patterns = {} | |
config.use_transactional_fixtures = false | |
config.before :all, :type => :request do | |
Rails.application.config.action_dispatch.show_exceptions = true | |
end | |
config.before :suite do | |
DatabaseCleaner.strategy = :transaction | |
end | |
config.after :all, :type => :request do | |
DatabaseCleaner.clean_with :truncation | |
load 'db/seeds.rb' | |
end | |
config.before :suite do | |
DatabaseCleaner.clean_with :truncation | |
load 'db/seeds.rb' | |
end | |
config.include(SaveAndOpenOnFail, :type => :request) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment