1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/spec/spec_helper.rb
Jared Beck df4f3bba4f Lint: Fix various offenses, mostly rspec
- Fix Lint/RescueWithoutErrorClass
  - And I use the term "fix" loosely
- Fix RSpec/PredicateMatcher
  - The failure message should actually be better this way too.
- RSpec/LetBeforeExamples
- RSpec/HookArgument
- Fix RSpec/ExpectInHook in widget_spec.rb
- Fix RSpec/MessageSpies
  - I like spies. I've never linted them before, but I like how they
    separate test setup from assertions.
2017-09-19 01:25:53 -04:00

78 lines
2.4 KiB
Ruby

require "pry"
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= "test"
ENV["DB"] ||= "sqlite"
unless File.exist?(File.expand_path("dummy_app/config/database.yml", __dir__))
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
end
RSpec.configure do |config|
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
# 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
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.disable_monkey_patching!
config.warnings = false
if config.files_to_run.one?
config.default_formatter = "doc"
end
config.order = :random
Kernel.srand config.seed
end
def active_record_gem_version
Gem::Version.new(ActiveRecord::VERSION::STRING)
end
# 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)
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new("5.0.0.beta1")
{ params: args }
else
args
end
end
require File.expand_path("../dummy_app/config/environment", __FILE__)
require "rspec/rails"
require "paper_trail/frameworks/rspec"
require "ffaker"
require "timecop"
# Run any available migration
ActiveRecord::Migrator.migrate File.expand_path("dummy_app/db/migrate/", __dir__)
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")
config.before { DatabaseCleaner.start }
config.after { DatabaseCleaner.clean }
end
end