Skip to content

Commit

Permalink
Consolidate RSpec settings in one file
Browse files Browse the repository at this point in the history
  • Loading branch information
subelsky committed Jul 20, 2017
1 parent b9a5228 commit e77f742
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--color
--require rails_helper
--require spec_helper
9 changes: 2 additions & 7 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ guard :rspec, cmd:"spring rspec" do
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch('spec/rails_helper.rb') { "spec" }
watch('spec/spec_helper.rb') { "spec" }

# Capybara features specs
#watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
#watch(%r{^spec/acceptance/(.+)\.feature$})
#watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
end

guard :bundler do
Expand All @@ -37,7 +33,6 @@ guard :bundler do
# watch(/^.+\.gemspec/)
end

guard 'brakeman', :run_on_start => true do
watch(%r{^app/.+\.(erb|haml|rhtml|rb)$})
watch(%r{^config/.+\.rb$})
watch(%r{^lib/.+\.rb$})
Expand Down
41 changes: 0 additions & 41 deletions spec/rails_helper.rb

This file was deleted.

43 changes: 23 additions & 20 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production? # Extra check to prevent database changes if the environment is production

require 'rspec/rails'
require 'devise'
require 'webmock/rspec'
require 'capybara/rspec'
require "codeclimate-test-reporter"
require 'airborne'
require 'vcr'
require "pathname"

CodeClimate::TestReporter.start
SPEC_DATA_PATH = Pathname(__dir__).join("data")

Dir[Rails.root.join('spec/support/**/*.rb')].each { |file| require file }
CodeClimate::TestReporter.start
Dir[Rails.root.join("spec/support/**/*.rb")].each { |file| require file }

RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include Coyote::FeatureUserLogin, :type => :feature
config.include Coyote::RequestHeaders
config.include Coyote::RequestHeaders
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
config.include Devise::TestHelpers, :type => :view

config.order = "random"
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!
config.infer_spec_type_from_file_location!
config.infer_base_class_for_anonymous_controllers = false
config.use_transactional_fixtures = false

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
Expand All @@ -26,12 +41,6 @@
mocks.verify_partial_doubles = true
end

config.order = 'random'

config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!

config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
Expand All @@ -41,28 +50,22 @@
end

config.before(:each,:type => :feature) do
# :rack_test driver's Rack app under test shares database connection
# with the specs, so continue to use transaction strategy for speed.
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test

if !driver_shares_db_connection_with_specs
unless Capybara.current_driver == :rack_test
# Driver is probably for an external browser with an app
# under test that does *not* share a database connection with the
# specs, so use truncation strategy.
# specs, so use truncation strategy. With rack, we can get away with transactions.
DatabaseCleaner.strategy = :truncation
end
end

config.before(:each,:type => [:request,:feature]) do
config.around(:each,type: %i(request feature)) do |example|
DatabaseCleaner.start
end

config.append_after(:each,:type => [:request,:feature]) do
example.run
DatabaseCleaner.clean
end
end

SPEC_DATA_PATH = Pathname(__dir__).join("data")
ActiveRecord::Migration.maintain_test_schema!

VCR.configure do |config|
config.cassette_library_dir = "vcr"
Expand Down

0 comments on commit e77f742

Please sign in to comment.