Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCHI WAI YIP
10,438 Pointsundefined method `sign_in'
Can't fix the Error by following the course...
1) Viewing todo items displays the title of the todo list
Failure/Error: before { sign_in user, password: 'treehouse1'}
NoMethodError:
undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fedd5abda40>
# ./spec/features/todo_items/index_spec.rb:6:in `block (2 levels) in <top (required)>'
I set the method in the authenication_helpers.rb
module AuthenticationHelpers
module Controller
def sign_in(user)
controller.stub(:current_user).and_return(user)
controller.stub(:user_id).and_return(user.id)
end
end
module Feature
def sign_in(user, options ={})
visit "/login"
fill_in "Email", with: user.email
fill_in "Password", with: options[:password]
click_button "Log In"
end
end
end
And added config to spec_helper.rb
RSpec.configure do |config|
config.include TodoListHelpers, type: :feature
config.include RailsDomIdHelper, type: :feature
config.include FactoryGirl::Syntax::Methods
config.include AuthenticationHelpers::Controller, tpye: :controller
config.include AuthenticationHelpers::Feature, tpye: :feature
But rspec can't define the method
let(:user) {create (:user)}
before { sign_in user, password: 'treehouse1'}
# And I tried before do too.. the error is same
before do
sign_in user, password: "treehouse1"
end
1 Answer
Raymond Sapida
33,049 PointsHi there,
It looks like you have a typo in the last two lines of your spec_helper
config.include AuthenticationHelpers::Controller, tpye: :controller
config.include AuthenticationHelpers::Feature, tpye: :feature
I hope this fixes it and if not, it might have something to do with the directory you added the authentication helper to. Good luck!