Skip to content

Instantly share code, notes, and snippets.

@jkriss
Created January 14, 2010 00:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkriss/276717 to your computer and use it in GitHub Desktop.
Save jkriss/276717 to your computer and use it in GitHub Desktop.
an example env.rb file for cucumber, safariwatir, and machinist
# 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