Skip to content

Instantly share code, notes, and snippets.

@diabolo
Created September 9, 2009 15:52
Show Gist options
  • Save diabolo/183833 to your computer and use it in GitHub Desktop.
Save diabolo/183833 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'spork'
Spork.prefork do
# Sets up the Rails environment for Cucumber
ENV["RAILS_ENV"] = "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "textmate_formatter"))
require 'webrat'
require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false
end
#require 'cucumber/rails/world'
require 'webrat/core/matchers'
require 'cucumber'
require 'cucumber/formatter/unicode'
require 'spec/rails'
require 'cucumber/rails/rspec'
require 'features/support/hooks'
require 'tempfile'
require 'database_cleaner'
module WebratWorld
def peek_body(text,options = {})
puts CodeRay.scan(text, :html).term
end
def mate(text, options = {})
file = Tempfile.new('mate')
file.write text
system("mate -w #{f.path}")
end
def vim(text, options = {})
file = Tempfile.new('random')
file.write text
system("vim #{file.path}")
end
def mvim(text, options = {})
file = Tempfile.new('random')
file.write text
system("mvim #{file.path}")
end
end
World(WebratWorld)
DECIMAL_NUMBER_RGX = '\d+(?:[.]\d{2})?'
class String
def remove_non_ascii
self.gsub(/[\x80-\xff]/,'-')
end
end
end
Spork.each_run do
# Make visible for testing
ApplicationController.send(:public, :logged_in?, :current_user, :authorized?)
Cucumber::Rails.bypass_rescue unless defined? NoBypass
# Comment out this line if you want Rails own error handling
# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
DatabaseCleaner.clean_with :truncation # clean once to ensure clean slate
DatabaseCleaner.strategy = :transaction
Before('@dbc') do
DatabaseCleaner.strategy = :truncation
end
Before do
DatabaseCleaner.start
end
After do
DatabaseCleaner.clean
end
After('@dbc') do
DatabaseCleaner.strategy = :transaction
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment