Created
August 24, 2013 04:25
-
-
Save saboyutaka/6326049 to your computer and use it in GitHub Desktop.
Rspec spec/support files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.include Devise::TestHelpers, :type => :controller | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.render_views | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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