Skip to content

Instantly share code, notes, and snippets.

@rrmartins
Created August 3, 2012 01:58
Show Gist options
  • Save rrmartins/3243400 to your computer and use it in GitHub Desktop.
Save rrmartins/3243400 to your computer and use it in GitHub Desktop.
Error Devise with RSpec and Rails 3
require 'spec_helper'
describe ContaPagarsController do
render_views
login_user
it "should have a current_user" do
subject.current_user.should_not be_nil
end
it "should get index" do
get 'index'
response.should be_success
end
describe "POST 'create'" do
it "creates link"
it "saves link"
it "redirects to link overview"
it "displays message"
end
end
module ControllerMacros
def login_user
before(:each) do
require 'pry'
binding.pry
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
user.confirm!
sign_in user
end
end
end
.../spec/spec_helper.rb:27:in `block (2 levels) in <top (required)>': uninitialized constant ControllerMacros (NameError)
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.mock_with :rspec
config.color_enabled = true
config.formatter = 'documentation'
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
end
@Olefine
Copy link

Olefine commented Jul 12, 2013

config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller

it's should not be in spec_helper file. Right place for it, is devise.rb in spec/support folder

@nclsjstnn
Copy link

i add require 'support/controller_macros' on top of spec/rails_helper.rb

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