Skip to content

Instantly share code, notes, and snippets.

@olkeene
Created November 11, 2015 14:13
Show Gist options
  • Select an option

  • Save olkeene/38a26eded549a2ef121f to your computer and use it in GitHub Desktop.

Select an option

Save olkeene/38a26eded549a2ef121f to your computer and use it in GitHub Desktop.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
# ES specs
require 'chewy/rspec'
if ENV['DRIVER'] == "selenium"
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :firefox)
end
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
else
# install manual https://github.com/teampoltergeist/poltergeist
require 'capybara-screenshot/rspec'
require 'capybara/poltergeist'
Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|
"screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"
end
# Keep only the screenshots generated from the last failing test suite
Capybara::Screenshot.prune_strategy = :keep_last_run
# ajax wait time
Capybara.default_wait_time = 20 # sec
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, timeout: 10000, js_errors: false, phantomjs_options: %w[--load-images=no])
end
Capybara.register_driver :poltergeist_debug do |app|
Capybara::Poltergeist::Driver.new(app, debug: true, timeout: 10000, js_errors: false, phantomjs_options: %w[--load-images=no --debug=true])
end
Capybara.javascript_driver = ENV['DEBUG'] == "1" ? :poltergeist_debug : :poltergeist
end
# 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 }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.allow_http_connections_when_no_cassette = true
c.hook_into :webmock
c.configure_rspec_metadata!
end
#require 'sms_spec'
require 'database_cleaner'
# data seed
require Rails.root.join('db','seeds')
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
config.include FeatureHelper, type: :feature
config.include MailerHelper
config.include Draper::DeviseHelper, type: :feature
config.include FactoryGirl::Syntax::Methods
config.include Requests::JsonHelpers, type: :controller
config.before do
allow(TwilioSms.instance).to receive_messages(send_sms: nil ) # return nil
allow(MixpanelHelper).to receive_messages(update_profile: nil ) # return nil
end
# config.treat_symbols_as_metadata_keys_with_true_values = true
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# 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
config.add_setting(:seed_tables)
config.seed_tables = %w(schema_migrations categories cities countries groups users)
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation, {except: config.seed_tables})
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
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
config.infer_spec_type_from_file_location!
#config.raise_errors_for_deprecations!
# 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" Done within rake test:specs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment