Advertisement
Guest User

Untitled

a guest
Feb 10th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 3.80 KB | None | 0 0
  1. require 'paperclip/matchers'
  2. require 'capybara/poltergeist'
  3.  
  4. def start_simplecov
  5.   require 'simplecov'
  6.   SimpleCov.start 'rails'
  7. end
  8.  
  9. def set_capybara_options
  10.   return unless example.metadata[:js]
  11.   host = "subdomain.#{Figaro.env.app_domain}"
  12.   port = 59947
  13.   Capybara.app_host = "http://#{host}:#{port}"
  14.   Capybara.server_port = port
  15. end
  16.  
  17. def use_truncation?
  18.   example.metadata[:request] || example.metadata[:truncation] || example.metadata[:js]
  19. end
  20.  
  21. def db_cleaner_strategy
  22.   use_truncation? ? :truncation : :transaction
  23. end
  24.  
  25. def sporkify(&block)
  26.   require 'spork'
  27.  
  28.   Spork.prefork do
  29.     yield
  30.   end
  31.  
  32.   Spork.each_run do
  33.     include ActionDispatch::TestProcess
  34.     start_simplecov if ENV['DRB']
  35.   end
  36. end
  37.  
  38. sporkify do
  39.   start_simplecov unless ENV['DRB']
  40.  
  41.   ENV["RAILS_ENV"] ||= 'test'
  42.   require File.expand_path("../../config/environment", __FILE__)
  43.   require 'rspec/rails'
  44.   require 'rspec/autorun'
  45.   require 'factory_girl'
  46.   require 'vcr'
  47.   require 'sidekiq/testing'
  48.  
  49.   Capybara.default_host = "http://subdomain.#{Figaro.env.app_domain}"
  50.   Capybara.register_driver :poltergeist do |app|
  51.     Capybara::Poltergeist::Driver.new(app, { debug: false, js_errors: false, phantomjs_logger: File.open(File::NULL, "w") })
  52.   end
  53.   Capybara.javascript_driver = :poltergeist
  54.  
  55.   # Requires supporting ruby files with custom matchers and macros, etc,
  56.   # in spec/support/ and its subdirectories.
  57.   Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  58.  
  59.   RSpec.configure do |config|
  60.     config.fixture_path = "#{::Rails.root}/spec/fixtures"
  61.  
  62.     # needed to pass :vcr, not needed in RSpec 3
  63.     config.treat_symbols_as_metadata_keys_with_true_values = true
  64.  
  65.     # If you're not using ActiveRecord, or you'd prefer not to run each of your
  66.     # examples within a transaction, remove the following line or assign false
  67.     # instead of true.
  68.     config.use_transactional_fixtures = false
  69.  
  70.     # Database Cleaner
  71.     require 'database_cleaner'
  72.     config.before(:suite) do
  73.       DatabaseCleaner.strategy = :transaction
  74.       DatabaseCleaner.clean_with :truncation
  75.     end
  76.     config.before(:each) do
  77.       DatabaseCleaner.strategy = db_cleaner_strategy
  78.       DatabaseCleaner.start
  79.       set_capybara_options
  80.     end
  81.     config.after(:each) do
  82.       DatabaseCleaner.clean
  83.       $redis.flushdb
  84.  
  85.       # clear all sidekiq worker's jobs
  86.       Sidekiq::Worker.clear_all
  87.     end
  88.  
  89.     # If true, the base class of anonymous controllers will be inferred
  90.     # automatically. This will be the default behavior in future versions of
  91.     # rspec-rails.
  92.     config.infer_base_class_for_anonymous_controllers = false
  93.  
  94.     # Run specs in random order to surface order dependencies. If you find an
  95.     # order dependency and want to debug it, you can fix the order by providing
  96.     # the seed, which is printed after each run.
  97.     #     --seed 1234
  98.     config.order = "random"
  99.  
  100.     # Mailers
  101.     ActionMailer::Base.delivery_method = :test
  102.     config.include(MailerMacros)
  103.     config.before(:each) { reset_email }
  104.  
  105.     # Add FactoryGirl methods
  106.     config.include FactoryGirl::Syntax::Methods
  107.  
  108.     # Add routing URL helpers
  109.     config.include Rails.application.routes.url_helpers
  110.     Rails.application.default_url_options[:host] = "sentrylink.#{Figaro.env.app_domain}"
  111.  
  112.     config.include Helpers
  113.     config.include Paperclip::Shoulda::Matchers
  114.     config.include CapybaraSupport, type: :feature
  115.  
  116.     config.before(:each) do
  117.       timezone = double("timezone", :zone => "America/New_York")
  118.       Timezone::Zone.stub(:new).and_return(timezone)
  119.     end
  120.  
  121.     config.include Warden, type: :feature
  122.   end
  123.  
  124.   VCR.configure do |c|
  125.     c.cassette_library_dir = 'spec/cassettes'
  126.     c.hook_into :fakeweb
  127.     c.configure_rspec_metadata!
  128.     c.ignore_localhost = true
  129.   end
  130.  
  131.   Fog.mock!
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement