Skip to content

Instantly share code, notes, and snippets.

@parndt
Created January 17, 2012 22:17
Show Gist options
  • Save parndt/1629346 to your computer and use it in GitHub Desktop.
Save parndt/1629346 to your computer and use it in GitHub Desktop.
RSpec support for edge Refinery apps
engines = Dir[File.expand_path('../vendor/engines/*', __FILE__)]
guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
watch(%r{^spec/support/.+\.rb$})
engines.each do |engine|
watch(%r{^#{engine}/spec/support/.+\.rb$})
end
end
guard 'rspec', :version => 2, :spec_paths => engines.map{|e| "#{e}/spec"},
:cli => (File.read('.rspec').split("\n").join(' ') if File.exists?('.rspec')) do
engines.each do |engine|
watch(%r{^#{engine}/spec/.+_spec\.rb$})
watch(%r{^#{engine}/app/(.+)\.rb$}) { |m| "#{engine}/spec/#{m[1]}_spec.rb" }
watch(%r{^#{engine}/lib/(.+)\.rb$}) { |m| "#{engine}/spec/lib/#{m[1]}_spec.rb" }
watch(%r{^#{engine}/app/controllers/(.+)_(controller)\.rb$}) { |m| ["#{engine}/spec/routing/#{m[1]}_routing_spec.rb", "#{engine}/spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "#{engine}/spec/requests/#{m[1]}_spec.rb"] }
watch(%r{^#{engine}/spec/support/(.+)\.rb$}) { "#{engine}/spec" }
watch("#{engine}/spec/spec_helper.rb") { "#{engine}/spec" }
watch("#{engine}/config/routes.rb") { "#{engine}/spec/routing" }
watch("#{engine}/app/controllers/application_controller.rb") { "#{engine}/spec/controllers" }
# Capybara request specs
watch(%r{^#{engine}/app/views/(.+)/.*\.(erb|haml)$}) { |m| "#{engine}/spec/requests/#{m[1]}_spec.rb" }
end
end
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') unless defined?(ENGINE_RAILS_ROOT)
def setup_environment
# Configure Rails Environment
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
Rails.backtrace_cleaner.remove_silencers!
RSpec.configure do |config|
config.mock_with :rspec
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
# set javascript driver for capybara
Capybara.javascript_driver = :webkit
# minimize password hashing stretches
Devise.stretches = 1
end
def each_run
FactoryGirl.reload
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories including factories.
([ENGINE_RAILS_ROOT, Rails.root.to_s].uniq | ::Refinery::Plugins.registered.pathnames).map{|p|
Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
}.flatten.sort.each do |support_file|
require support_file
end
end
# If spork is available in the Gemfile it'll be used but we don't force it.
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
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.
setup_environment
end
Spork.each_run do
# This code will be run each time you run your specs.
each_run
end
else
setup_environment
each_run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment