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 trialAnthony Quisenberry
13,074 Pointshow do I fake a log in for a feature test?
The code that is used in the video does not work for feature tests. can someone please set me on a path in a somewhat right direction
1 Answer
Nick Fuller
9,027 PointsThere are a few ways to do this.
Using capybara you can simply do
before do
visit "/users/sign_in"
fill_in "user[email]", with: email
fill_in "user[password]", with: password
click_button "Log In"
end
If you're using Devise you can read this https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
Or what I would suggest is create a spec helper method, that takes an argument which would be a user object (usually created by a factory), called login(user)
which you can then re-use throughout your features.