rails_helper.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ENV['RAILS_ENV'] ||= 'test'
  2. if ENV['COVERAGE']
  3. require 'simplecov'
  4. SimpleCov.start 'rails'
  5. elsif ENV['CI'] == 'true'
  6. require 'simplecov'
  7. SimpleCov.start 'rails' do
  8. require 'simplecov-lcov'
  9. SimpleCov::Formatter::LcovFormatter.config do |c|
  10. c.report_with_single_file = true
  11. c.single_report_path = 'coverage/lcov.info'
  12. end
  13. formatter SimpleCov::Formatter::LcovFormatter
  14. add_filter %w[version.rb initializer.rb]
  15. end
  16. end
  17. # require File.expand_path('../config/environment', __dir__)
  18. require_relative '../config/environment'
  19. require 'rspec/rails'
  20. require 'webmock/rspec'
  21. WebMock.disable_net_connect!(allow_localhost: true)
  22. # Requires supporting ruby files with custom matchers and macros, etc,
  23. # in spec/support/ and its subdirectories.
  24. Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
  25. ActiveRecord::Migration.maintain_test_schema!
  26. # Mix in shoulda matchers
  27. Shoulda::Matchers.configure do |config|
  28. config.integrate do |with|
  29. with.test_framework :rspec
  30. with.library :rails
  31. end
  32. end
  33. RSpec.configure do |config|
  34. config.mock_with :rspec
  35. # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  36. config.fixture_path = config.file_fixture_path = "#{::Rails.root}/spec/fixtures"
  37. # If you're not using ActiveRecord, or you'd prefer not to run each of your
  38. # examples within a transaction, remove the following line or assign false
  39. # instead of true.
  40. config.use_transactional_fixtures = true
  41. # rspec-rails 3 will no longer automatically infer an example group's spec type
  42. # from the file location. You can explicitly opt-in to this feature using this
  43. # snippet:
  44. config.infer_spec_type_from_file_location!
  45. # If true, the base class of anonymous controllers will be inferred
  46. # automatically. This will be the default behavior in future versions of
  47. # rspec-rails.
  48. config.infer_base_class_for_anonymous_controllers = false
  49. # These two settings work together to allow you to limit a spec run
  50. # to individual examples or groups you care about by tagging them with
  51. # `:focus` metadata. When nothing is tagged with `:focus`, all examples
  52. # get run.
  53. config.filter_run :focus if ENV['CI'] != 'true'
  54. config.run_all_when_everything_filtered = true
  55. # Run specs in random order to surface order dependencies. If you find an
  56. # order dependency and want to debug it, you can fix the order by providing
  57. # the seed, which is printed after each run.
  58. # --seed 1234
  59. config.order = 'random'
  60. config.global_fixtures = :all
  61. config.render_views
  62. config.example_status_persistence_file_path = './spec/examples.txt'
  63. config.include Devise::Test::ControllerHelpers, type: :controller
  64. config.include SpecHelpers
  65. config.include ActiveSupport::Testing::TimeHelpers
  66. end
  67. require 'capybara_helper' if ENV['RSPEC_TASK'] != 'spec:nofeatures'