Created
August 25, 2011 03:41
-
-
Save ckazu/1169929 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# coding: utf-8 | |
require 'spork' | |
Spork.prefork do | |
# Loading more in this block will cause your tests to run faster. However, | |
# if you change any configuration or code from libraries loaded here, you'll | |
# need to restart spork for it take effect. | |
# This file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require Rails.root.join("spec/factories.rb") | |
require 'rspec/rails' | |
require 'capybara/rspec' | |
require 'test_xml/spec' | |
require "selenium/client" | |
# Requires supporting ruby files with custom matchers and macros, etc, | |
# in spec/support/ and its subdirectories. | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
RSpec.configure do |config| | |
# == Mock Framework | |
# | |
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: | |
# | |
# config.mock_with :mocha | |
# config.mock_with :flexmock | |
# config.mock_with :rr | |
config.mock_with :rspec | |
config.fixture_path = "#{::Rails.root}/spec/fixtures" | |
# If you're not using ActiveRecord, or you'd prefer not to run each of your | |
# examples within a transaction, comment the following line or assign false | |
# instead of true. | |
config.use_transactional_fixtures = true | |
#config.filter_run :focus => true | |
if Spork.using_spork? | |
### Part of a Spork hack. See http://bit.ly/arY19y | |
# Emulate initializer set_clear_dependencies_hook in | |
# railties/lib/rails/application/bootstrap.rb | |
ActiveSupport::Dependencies.clear | |
end | |
# config.use_transactional_fixtures = false | |
config.before :each do | |
if Capybara.current_driver == :rack_test | |
DatabaseCleaner.strategy = :transaction | |
else | |
DatabaseCleaner.strategy = :truncation | |
end | |
# DatabaseCleaner.start | |
end | |
config.after :each do | |
# DatabaseCleaner.clean | |
end | |
# register selenium spec directory | |
config.include SeleniumExampleGroup, :type => :selenium, :example_group => { | |
:file_path => config.escaped_path(%w[spec selenium]) | |
} | |
Capybara.javascript_driver = :webkit | |
end | |
# | |
# quick monkey patch for rcov | |
# | |
# http://codefluency.com/post/1023734493/a-bandaid-for-rcov-on-ruby-1-9 | |
# | |
if defined?(Rcov) | |
class Rcov::CodeCoverageAnalyzer | |
def update_script_lines__ | |
if '1.9'.respond_to?(:force_encoding) | |
SCRIPT_LINES__.each do |k,v| | |
v.each { |src| src.force_encoding('utf-8') } | |
end | |
end | |
@script_lines__ = @script_lines__.merge(SCRIPT_LINES__) | |
end | |
end | |
end | |
end | |
Spork.each_run do | |
# processing RSpec tags | |
# [FIXME] not work on spork. | |
RSpec.configure do |config| | |
# to run this spec: | |
# $ rspec --tag selenium spec/some_spec.rb | |
config.filter_run_excluding :selenium=>true unless config.inclusion_filter[:selenium] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment