rails_helper.rb 2.8 KB

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