Created
June 29, 2011 09:09
-
-
Save Bregor/1053489 to your computer and use it in GitHub Desktop.
Capybara request helpers for devise
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' | |
describe "HistoryItems" do | |
before(:each) {login_as :user} | |
describe "GET /history_items" do | |
it "works!" do | |
visit history_items_path | |
response.should be_success | |
end | |
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 'rubygems' | |
require 'spork' | |
Spork.prefork do | |
# Loading more in this block will cause your tests to run faster. However, | |
# if you change any configuration or code from libraries loaded here, you'll | |
# need to restart spork for it take effect. | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
require 'capybara/rspec' | |
require 'capybara/rails' | |
end | |
Spork.each_run do | |
# This code will be run each time you run your specs. | |
Dir["#{File.dirname(__FILE__)}/fabricators/**/*.rb"].each { |e| require e } | |
end | |
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
config.use_transactional_fixtures = true | |
config.use_transactional_examples = true | |
config.include Devise::TestHelpers, :type => :controller | |
config.include Devise::SpecHelpers, :type => :controller | |
config.include HelperMethods, :type => :request | |
end | |
Capybara.javascript_driver = :webkit |
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" | |
module HelperMethods | |
def logout_user(user = @current_user) | |
Capybara.reset_sessions! | |
visit destroy_user_session_url | |
end | |
def login_as(sym) | |
logout_user if @current_user | |
@current_user = Fabricator sym.to_sym | |
visit new_user_session_url | |
fill_in I18n.t('activerecord.attributes.user.email'), :with => @current_user.email | |
fill_in I18n.t('activerecord.attributes.user.password'), :with => @current_user.password | |
click_button I18n.t('devise.shared.links.sign_in') end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@albandiguer you're welcome ;)