Skip to content

Instantly share code, notes, and snippets.

@dcvezzani
Created April 3, 2013 22:27
Show Gist options
  • Save dcvezzani/5306034 to your computer and use it in GitHub Desktop.
Save dcvezzani/5306034 to your computer and use it in GitHub Desktop.
The features/support/env.rb file provides configurations for running cucumber tests. Spork is used here to speed up the tests (or specifically, loading the environment for the tests). Spork and Cucumber both have blocks that may be used to judiciously load information or reset the database. 'Before' and 'After' blocks are run for each cucumber s…
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
...
require File.expand_path("./config/environment.rb")
...
Spork.prefork do
...
ActionController::Base.allow_rescue = false
...
Before('@no-txn,@selenium,@culerity,@celerity') do
# I added this block and changed to transaction because @javascript was truncating most of my tables
#DatabaseCleaner.strategy = :truncation, {:except => %w[groups]}
DatabaseCleaner.strategy = :truncation
end
# <<< 2: runs for each @javascript scenario
# leave these :except tables alone; they shouldn't be changing and so they don't need to be truncated
# is there such a thing as :only option? Perhaps that would be a better approach.
Before('@javascript') do
DatabaseCleaner.strategy = :truncation, {:except => %w[groups categories category_types content_types content_type_groups]}
end
end
Spork.each_run do
# This code will be run each time you run your specs.
ActionController::Base.allow_rescue = false
Cucumber::Rails::World.use_transactional_fixtures = true
if defined?(ActiveRecord::Base)
begin
DatabaseCleaner.clean_with :truncation
silence_stream(STDOUT) do
require File.join(File.dirname(__FILE__), '../../db/seeds.rb') # <<< 1: db/seeds.rb loaded
end
DatabaseCleaner.strategy = :transaction
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment