2017-06-10 01:28:48 -04:00
|
|
|
require "pry"
|
|
|
|
|
2017-05-30 00:58:26 -04:00
|
|
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
|
|
|
ENV["RAILS_ENV"] ||= "test"
|
|
|
|
ENV["DB"] ||= "sqlite"
|
|
|
|
|
2017-06-10 01:28:48 -04:00
|
|
|
unless File.exist?(File.expand_path("dummy_app/config/database.yml", __dir__))
|
2017-05-30 00:58:26 -04:00
|
|
|
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
|
|
|
|
end
|
|
|
|
|
2013-04-10 13:58:39 -04:00
|
|
|
RSpec.configure do |config|
|
2014-10-09 15:04:17 -04:00
|
|
|
config.expect_with :rspec do |expectations|
|
|
|
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
|
|
end
|
|
|
|
|
|
|
|
config.mock_with :rspec do |mocks|
|
|
|
|
mocks.verify_partial_doubles = true
|
|
|
|
end
|
2013-04-10 13:58:39 -04:00
|
|
|
|
2015-12-24 01:50:14 -05:00
|
|
|
# Support for disabling `verify_partial_doubles` on specific examples.
|
|
|
|
config.around(:each, verify_stubs: false) do |ex|
|
|
|
|
config.mock_with :rspec do |mocks|
|
|
|
|
mocks.verify_partial_doubles = false
|
|
|
|
ex.run
|
|
|
|
mocks.verify_partial_doubles = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-21 01:41:20 -04:00
|
|
|
config.filter_run :focus
|
|
|
|
config.run_all_when_everything_filtered = true
|
|
|
|
config.disable_monkey_patching!
|
2017-05-21 01:29:58 -04:00
|
|
|
config.warnings = false
|
2017-05-21 01:41:20 -04:00
|
|
|
if config.files_to_run.one?
|
|
|
|
config.default_formatter = "doc"
|
|
|
|
end
|
2017-05-21 01:47:53 -04:00
|
|
|
config.order = :random
|
|
|
|
Kernel.srand config.seed
|
2013-04-10 13:58:39 -04:00
|
|
|
end
|
2016-01-11 22:07:57 -05:00
|
|
|
|
2016-02-15 18:27:57 -05:00
|
|
|
def active_record_gem_version
|
|
|
|
Gem::Version.new(ActiveRecord::VERSION::STRING)
|
|
|
|
end
|
|
|
|
|
2016-01-11 22:07:57 -05:00
|
|
|
# Wrap args in a hash to support the ActionController::TestCase and
|
|
|
|
# ActionDispatch::Integration HTTP request method switch to keyword args
|
|
|
|
# (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
|
|
|
|
def params_wrapper(args)
|
2016-03-05 17:07:32 -05:00
|
|
|
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
|
2016-01-11 22:07:57 -05:00
|
|
|
{ params: args }
|
|
|
|
else
|
|
|
|
args
|
|
|
|
end
|
2016-02-15 18:27:57 -05:00
|
|
|
end
|
2017-05-30 00:58:26 -04:00
|
|
|
|
2017-06-10 01:28:48 -04:00
|
|
|
require File.expand_path("../dummy_app/config/environment", __FILE__)
|
2017-05-30 00:58:26 -04:00
|
|
|
require "rspec/rails"
|
|
|
|
require "paper_trail/frameworks/rspec"
|
|
|
|
require "ffaker"
|
|
|
|
require "timecop"
|
|
|
|
|
2017-06-10 01:28:48 -04:00
|
|
|
# Run any available migration
|
|
|
|
ActiveRecord::Migrator.migrate File.expand_path("dummy_app/db/migrate/", __dir__)
|
2017-05-30 00:58:26 -04:00
|
|
|
|
|
|
|
require "database_cleaner"
|
|
|
|
DatabaseCleaner.strategy = :truncation
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
|
|
|
config.use_transactional_fixtures = active_record_gem_version >= ::Gem::Version.new("5")
|
|
|
|
|
|
|
|
# In rails < 5, some tests seem to require DatabaseCleaner-truncation.
|
|
|
|
# Truncation is about three times slower than transaction rollback, so it'll
|
|
|
|
# be nice when we can drop support for rails < 5.
|
|
|
|
if active_record_gem_version < ::Gem::Version.new("5")
|
2017-09-18 23:56:07 -04:00
|
|
|
config.before { DatabaseCleaner.start }
|
|
|
|
config.after { DatabaseCleaner.clean }
|
2017-05-30 00:58:26 -04:00
|
|
|
end
|
|
|
|
end
|