I've got a cucumber,ruby,siteprism project where we're using the 'rspec' gem to check expectations. This is included in our env.rb and used successfully in the step definitions.
I was now trying to make some assertions in a SitePrism class but I am getting an error. Do you know how I could use those expect() methods?
I tried with require 'rspec'
plus include Rspec
in the .rb file which is defining the SitePrism class, but I got the same error still:
expect(local_value).to eq(@previous_value)
=> Error: NoMethodError: undefined method `expect' for #<xxx_Object @loaded=false>
Thank you!
As you've discovered (from your comment) you can include RSpec::Matchers
in your page object class to get expect
along with RSpecs default matchers. One of those matchers is named all
which then shadows the Capybara::DSL all
method that previously included into the object, and produces the error you're seeing. The way to solve that is to call the Capybara version of all
on the current_session object (page
) or the alias 'find_all'. So all(...).map(...)
becomes
page.all(...).map(...) # Same as Capybara.current_session.all(...)...
or
find_all(...).map(...) # or page.find_all ...