Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'paperclip/matchers'
- require 'capybara/poltergeist'
- def start_simplecov
- require 'simplecov'
- SimpleCov.start 'rails'
- end
- def set_capybara_options
- return unless example.metadata[:js]
- host = "subdomain.#{Figaro.env.app_domain}"
- port = 59947
- Capybara.app_host = "http://#{host}:#{port}"
- Capybara.server_port = port
- end
- def use_truncation?
- example.metadata[:request] || example.metadata[:truncation] || example.metadata[:js]
- end
- def db_cleaner_strategy
- use_truncation? ? :truncation : :transaction
- end
- def sporkify(&block)
- require 'spork'
- Spork.prefork do
- yield
- end
- Spork.each_run do
- include ActionDispatch::TestProcess
- start_simplecov if ENV['DRB']
- end
- end
- sporkify do
- start_simplecov unless ENV['DRB']
- ENV["RAILS_ENV"] ||= 'test'
- require File.expand_path("../../config/environment", __FILE__)
- require 'rspec/rails'
- require 'rspec/autorun'
- require 'factory_girl'
- require 'vcr'
- require 'sidekiq/testing'
- Capybara.default_host = "http://subdomain.#{Figaro.env.app_domain}"
- Capybara.register_driver :poltergeist do |app|
- Capybara::Poltergeist::Driver.new(app, { debug: false, js_errors: false, phantomjs_logger: File.open(File::NULL, "w") })
- end
- Capybara.javascript_driver = :poltergeist
- # Requires supporting ruby files with custom matchers and macros, etc,
- # in spec/support/ and its subdirectories.
- Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
- RSpec.configure do |config|
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
- # needed to pass :vcr, not needed in RSpec 3
- config.treat_symbols_as_metadata_keys_with_true_values = true
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = false
- # Database Cleaner
- require 'database_cleaner'
- config.before(:suite) do
- DatabaseCleaner.strategy = :transaction
- DatabaseCleaner.clean_with :truncation
- end
- config.before(:each) do
- DatabaseCleaner.strategy = db_cleaner_strategy
- DatabaseCleaner.start
- set_capybara_options
- end
- config.after(:each) do
- DatabaseCleaner.clean
- $redis.flushdb
- # clear all sidekiq worker's jobs
- Sidekiq::Worker.clear_all
- end
- # If true, the base class of anonymous controllers will be inferred
- # automatically. This will be the default behavior in future versions of
- # rspec-rails.
- config.infer_base_class_for_anonymous_controllers = false
- # Run specs in random order to surface order dependencies. If you find an
- # order dependency and want to debug it, you can fix the order by providing
- # the seed, which is printed after each run.
- # --seed 1234
- config.order = "random"
- # Mailers
- ActionMailer::Base.delivery_method = :test
- config.include(MailerMacros)
- config.before(:each) { reset_email }
- # Add FactoryGirl methods
- config.include FactoryGirl::Syntax::Methods
- # Add routing URL helpers
- config.include Rails.application.routes.url_helpers
- Rails.application.default_url_options[:host] = "sentrylink.#{Figaro.env.app_domain}"
- config.include Helpers
- config.include Paperclip::Shoulda::Matchers
- config.include CapybaraSupport, type: :feature
- config.before(:each) do
- timezone = double("timezone", :zone => "America/New_York")
- Timezone::Zone.stub(:new).and_return(timezone)
- end
- config.include Warden, type: :feature
- end
- VCR.configure do |c|
- c.cassette_library_dir = 'spec/cassettes'
- c.hook_into :fakeweb
- c.configure_rspec_metadata!
- c.ignore_localhost = true
- end
- Fog.mock!
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement