Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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
end
end
end
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
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