Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Forked from christos/gist:39038
Created March 23, 2009 16:19
Show Gist options
  • Save balinterdi/83632 to your computer and use it in GitHub Desktop.
Save balinterdi/83632 to your computer and use it in GitHub Desktop.
#
# cucumber.yml
#
# Filter which features are run with each profile by the file extension
webrat: --require features/steps/common --require features/support/webrat_env.rb --exclude selenium.feature --format progress
selenium: --require features/steps/common --require features/support/selenium_env.rb --exclude webrat.feature --format progress
#
# features/support/env.rb
#
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails/world'
require 'cucumber/rails/rspec'
require 'webrat/rspec-rails'
#
# features/support/webrat_env.rb
#
require File.expand_path(File.dirname(__FILE__) + '/env.rb')
require 'webrat/rails'
require File.expand_path(File.dirname(__FILE__) + '/../../lib/webrat_hacks.rb')
Cucumber::Rails.use_transactional_fixtures
#
# features/support/selenium_env.rb
#
require File.expand_path(File.dirname(__FILE__) + '/env.rb')
require 'webrat/selenium'
require File.expand_path(File.dirname(__FILE__) + '/../../lib/webrat_hacks.rb')
World do
Webrat::Selenium::Rails::World.new
end
def empty_database
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute "DELETE FROM #{table}"
end
end
Before do
empty_database
selenium.delete_all_visible_cookies
ActionMailer::Base.deliveries = []
end
at_exit do
empty_database
end
#
# lib/webrat_hacks.rb
#
class Webrat::RailsSession
# This method returns the current location of the current page even if
# a redirection has ocurred. Not sure if there is already a method doing the same
# thing in webrat API.
#
# Useful to implement steps like: "Then I should have been redirected to the home page"
def request_path
integration_session.request.path
end
end
class Webrat::SeleniumSession
# Selenium version of request_path
def request_path
selenium.get_location.gsub("http://127.0.0.1:3001", "")
end
end
# Make the request_path method available to the steps
Webrat::Methods.delegate_to_session :request_path
module Webrat
# Start the app server using Polonium to enable access to ActionMailer.deliveries
# from acceptance tests while using Selenium, which is not possible if the
# server is started manually or the way webrat start it by default
def self.start_app_server
Polonium::Configuration.instance.app_server_runner.start
end
def self.stop_app_server
Polonium::Configuration.instance.app_server_runner.stop
end
# We prefer to start selenium server manually and keep it running to make
# the execution of features faster (especially using --browserSessionReuse)
def self.start_selenium_server
nil
end
def self.stop_selenium_server
nil
end
end
# Polonium configuration and initialization
Polonium::Configuration.instance.app_server_engine = :mongrel
Polonium::Configuration.instance.internal_app_server_port = 3001
Polonium::Configuration.instance.create_app_server_runner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment