Created
November 7, 2009 15:59
-
-
Save caifara/228757 to your computer and use it in GitHub Desktop.
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
# Sets up the Rails environment for Cucumber | |
ENV["RAILS_ENV"] = "test" | |
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') | |
require 'cucumber/rails/world' | |
require 'webrat' | |
require 'cucumber/rails/rspec' | |
require 'webrat/core/matchers' |
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
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
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
unless ENV['RAILS_ENV'] == "production" | |
namespace :selenium do | |
task(:env) do | |
system("osascript lib/applescript/start_selenium_env.scpt") | |
end | |
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
require File.expand_path(File.dirname(__FILE__) + '/env.rb') | |
require "webrat" | |
require 'webrat/selenium' | |
require 'rSquery' | |
# check what whether we use minimized js or not (we won't receive updates if it is) and whether the script/server has been started with cache_classes true | |
require File.expand_path(File.dirname(__FILE__) + '/check_selenium_env.rb') | |
require File.expand_path(File.dirname(__FILE__) + '/webrat_hacks.rb') | |
# At the moment we still don't a special selenium env, should change this in the near future | |
Webrat.configure do |config| | |
config.mode = :selenium | |
config.application_environment = :test | |
end | |
# This is helpful when using the same cucumber steps with differing methods for selenium and normal webrat | |
def selenium_env? | |
true | |
end | |
# Yes this is very basic but it works as we can't use transactions as the different ruby threads won't see db-changes | |
def empty_database | |
connection = ActiveRecord::Base.connection | |
connection.tables.each do |table| | |
connection.execute "DELETE FROM #{table}" | |
end | |
end | |
Cucumber::Rails::World.use_transactional_fixtures = false | |
Before do | |
empty_database | |
selenium.delete_all_visible_cookies # don't think this works, it's for when it does ..., you'll have to manually log out of you're application or restart FF for every single test | |
end | |
After do | |
# I have some rSquery and Selenium stuff here to log the user out after every scenario | |
end | |
at_exit do | |
empty_database | |
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
require File.expand_path(File.dirname(__FILE__) + '/env.rb') | |
require 'webrat' | |
Webrat.configure do |config| | |
config.mode = :rails | |
end | |
def selenium_env? | |
false | |
end | |
require File.expand_path(File.dirname(__FILE__) + '/webrat_hacks.rb') |
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
class Webrat::SeleniumSession | |
# Selenium version of request_path | |
def request_path | |
selenium.get_location.gsub("http://localhost:3001", "") | |
end | |
end | |
# Make the request_path method available to the steps | |
Webrat::Methods.delegate_to_session :request_path | |
module Webrat | |
module Selenium | |
module ApplicationServers | |
class Base | |
def boot | |
wait | |
end | |
end | |
end | |
end | |
end | |
module Webrat | |
module Selenium | |
class SeleniumRCServer | |
def boot | |
return if selenium_grid? | |
wait | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment