docbrown/spec/rails_helper.rb
Ben Halpern 921b5b0d9a
Add sloan as marker of low quality and adjust banishment logic (#1129)
* Add sloan as marker of low quality and adjust banishment logic

* Add s3 stub to rails_helper

* Modify banishment criteria

* Only mess with profile image in prod
2018-11-16 14:11:41 -05:00

102 lines
3.6 KiB
Ruby

ENV["RAILS_ENV"] = "test"
require "spec_helper"
require File.expand_path("../config/environment", __dir__)
require "rspec/rails"
abort("The Rails environment is running in production mode!") if Rails.env.production?
# Add additional requires below this line. Rails is not loaded until this point!
require "algolia/webmock"
require "pundit/matchers"
require "pundit/rspec"
require "stream_rails"
require "webmock/rspec"
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
# Disable internet connection with Webmock
WebMock.disable_net_connect!(allow_localhost: true)
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.include ApplicationHelper
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::IntegrationHelpers, type: :feature
config.include FactoryBot::Syntax::Methods
config.include OmniauthMacros
config.include RequestSpecHelper, type: :request
config.before do
ActiveRecord::Base.observers.disable :all # <-- Turn 'em all off!
end
# Only turn on VCR if :vcr is included metadata keys
config.around do |ex|
if ex.metadata.key?(:vcr)
ex.run
else
VCR.turned_off { ex.run }
end
end
# Allow testing with Stripe's test server. BECAREFUL
if config.filter_manager.inclusions.rules.include?(:live)
WebMock.allow_net_connect!
StripeMock.toggle_live(true)
puts "Running **live** tests against Stripe..."
end
config.before do
stub_request(:any, /res.cloudinary.com/).to_rack("dsdsdsds")
stub_request(:any, /s3.amazonaws.com/).to_rack("dsdsdsds")
stub_request(:post, /api.fastly.com/).
to_return(status: 200, body: "", headers: {})
stub_request(:post, /api.bufferapp.com/).
to_return(status: 200, body: { fake_text: "so fake" }.to_json, headers: {})
# stub_request(:any, /api.getstream.io/).to_rack(FakeStream)
# for twitter image cdn
stub_request(:get, /twimg.com/).
to_return(status: 200, body: "", headers: {})
stub_request(:any, /api.mailchimp.com/).
to_return(status: 200, body: "", headers: {})
stub_request(:post, /us-east-api.stream-io-api.com\/api\/v1.0\/feed\/user/).
to_return(status: 200, body: "{}", headers: {})
stub_request(:get, /us-east-api.stream-io-api.com\/api/).to_rack(FakeStream)
end
StreamRails.enabled = false
OmniAuth.config.test_mode = true
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end