Created
January 14, 2010 00:08
-
-
Save jkriss/276717 to your computer and use it in GitHub Desktop.
an example env.rb file for cucumber, safariwatir, and machinist
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"] ||= "cucumber" | |
require 'safariwatir' | |
require File.expand_path(File.dirname(__FILE__) + '/../../../config/environment') | |
require 'machinist' | |
require File.expand_path(File.dirname(__FILE__) + "/../../../test/blueprints") | |
ActionMailer::Base.default_url_options[:host] = "localhost" | |
ActionMailer::Base.default_url_options[:port] = "3000" | |
class WatirSession < ActionController::Integration::Session | |
def initialize(browser) | |
@browser = browser | |
super | |
end | |
def method_missing(method, *args, &block) | |
if @browser.respond_to?(method) | |
@browser.send(method, *args, &block) | |
else | |
raise NoMethodError.new("undefined method #{method} for #{self}", method, args) | |
end | |
end | |
end | |
class Watir::Safari | |
def visit(path) | |
uri = "http://localhost:3001#{path}" | |
goto(uri) | |
end | |
def fill_in(name_or_id, options) | |
find_text_field(name_or_id).set(options[:with]) | |
end | |
def click_button(value) | |
button(:value, value).click | |
end | |
def find_text_field(string) | |
text_field(:id, string) || text_field(:name, string) | |
end | |
end | |
browser = Watir::Safari.new | |
World do | |
WatirSession.new(browser) | |
end | |
Before do | |
ActiveRecord::Base.send(:subclasses).each do |model| | |
model.connection.execute("DELETE FROM #{model.table_name}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment