In two previous posts, I wrote about my frustrations with methods in Rails tests that just seem to float in space and appear out of nowhere, and that the Hartl tutorial mixes RSpec and Capybara, and that it would be nice to know which is which.
In the last post, I wrote that sometimes when you try to find which class contains a method you get “Object”, which is not very helpful.
puts "Here is method of sign_in: #{self.method(:sign_in).owner} " puts "Here is method of visit: #{self.method(:visit).owner} "
Here is method of sign_in: Object Here is method of visit: Capybara::DSL
In the root of the Rails tutorial app, you can run a grep command to find that method:
grep -rn 'def sign_in' *
app/helpers/sessions_helper.rb:3: def sign_in(user) spec/support/utilities.rb:3:def sign_in(user)
So here is the file spec/support/utilities.rb:
include ApplicationHelper def sign_in(user) visit signin_path fill_in "Email", with: user.email fill_in "Password", with: user.password click_button "Sign in" # puts "Here is method of click_button: #{self.method(:click_button).owner} - " # Sign in when not using Capybara as well. cookies[:remember_token] = user.remember_token end
As I stated, in app/helpers/sessions_helper.rb the method is in a module called SessionsHelper
Image from World Digital Library, assumed allowed under Fair Use. Image from the Psalter of Frederick II, a 13th century manuscript in the Byzantine style, housed at Riccardiana Library of Florence, aka Biblioteca Riccardiana.