More Ruby Testing Archaeology

I made some progress on this.

If something is a class, like “page” in the Hartl tutorial (like on say spec/requests/static_pages_spec.rb)
you could just do

puts "Here is page.class: #{page.class}"

which would give you

Here is page.class: Capybara::Session

I don’t know why I didn’t think of that before.

In that file he also calls some voodoo methods. In before do he has:

sign_in FactoryGirl.create(:user)


visit users_path

sign_in and visit are methods. You can get these by doing this:

meth = self.method(:sign_in)
puts "Here is method of sign_in: #{meth.owner}"
meth2 = self.method(:visit)
puts "Here is method of visit: #{meth2.owner}"

or you could do that on one line each like this:

puts "Here is method of sign_in: #{self.method(:sign_in).owner} "
puts "Here is method of visit: #{self.method(:visit).owner} "

Which will give you:

Here is method of sign_in: Object
Here is method of visit: Capybara::DSL

Granted, getting “Object” is not too helpful. But it is some progress.

Someone on the Rails core team has a post about finding methods here.