rails_helper.rb 2.5 KB

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