Reputation: 5182
How is it that rspec feature tests implicitly know to use methods such as find
, within
, and fill_in
from the page object?
I've written a helper class for some of my rspec tests and wanted to use those methods, and realized that I needed to pass the page object into the method, and then use page.find
and the like.
Upvotes: 1
Views: 259
Reputation: 34135
suppose you want to include the following module:
module MailerMacros
def last_email
ActionMailer::Base.deliveries.last
end
def reset_email
ActionMailer::Base.deliveries = []
end
end
to include them, just call config.include(MailerMacros)
, like this:
RSpec.configure do |config|
config.include(MailerMacros)
end
now, you should be able to call reset_email()
& last_email
instead of MailerMacros::reset_email()
.
Upvotes: 0
Reputation: 29389
RSpec achieves this by including Capybara::DSL
in those cases where it wants those methods available. The module is pretty elegant, if you want to take a look at https://github.com/jnicklas/capybara/blob/f83edc2a515a3a4fd80eef090734d14de76580d3/lib/capybara/dsl.rb
Upvotes: 1