Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2011 09:09
Show Gist options
  • Save Bregor/1053489 to your computer and use it in GitHub Desktop.
Save Bregor/1053489 to your computer and use it in GitHub Desktop.
Capybara request helpers for devise
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
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'
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 }
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
Capybara.javascript_driver = :webkit
require "spec_helper"
module HelperMethods
def logout_user(user = @current_user)
visit destroy_user_session_url
def login_as(sym)
logout_user if @current_user
@current_user = Fabricator sym.to_sym
visit new_user_session_url
fill_in I18n.t(''), :with =>
fill_in I18n.t('activerecord.attributes.user.password'), :with => @current_user.password
click_button I18n.t('devise.shared.links.sign_in') end
Copy link

Thanks for this, it helped me

Copy link

Bregor commented May 7, 2012

@albandiguer you're welcome ;)

Copy link

Helped me, too. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment