Skip to content

Instantly share code, notes, and snippets.

@saboyutaka
Created August 24, 2013 04:25
Show Gist options
  • Save saboyutaka/6326049 to your computer and use it in GitHub Desktop.
Save saboyutaka/6326049 to your computer and use it in GitHub Desktop.
Rspec spec/support files.
module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
end
end
end
RSpec.configure do |config|
config.extend ControllerMacros, type: :controller
end
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
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
end
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
end
RSpec.configure do |config|
# Include Factory Girl syntax to simplify calls to factories
config.include FactoryGirl::Syntax::Methods
config.before(:suite) do
FactoryGirl.reload
end
end
require 'capybara/poltergeist'
Capybara.configure do |config|
config.javascript_driver = :poltergeist
config.default_wait_time = 10
config.register_driver :poltergeist do |app|
config::Poltergeist::Driver.new(app, :js_errors => false, :timeout => 60)
end
end
RSpec.configure do |config|
config.render_views
end
require 'spec_helper'
include Warden::Test::Helpers
module RequestHelper
def create_logged_in_user
user = Factory(:user)
login(user)
user
end
def login(user)
login_as user, scope: :user
end
end
RSpec.configure do |config|
config.include RequestHelper, type: :feature
end
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
# Support for Rspec / Capybara subdomain integration testing
def switch_to_subdomain(subdomain)
hostname = [subdomain, Rails.configuration.base_domain].reject(&:blank?).join(".")
Capybara.app_host = "http://#{hostname}"
end
def switch_to_main_domain
switch_to_subdomain nil
end
RSpec.configure do |config|
switch_to_main_domain
end
Capybara.configure do |config|
config.always_include_port = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment