2

I have a module which i have included into my main class:

module GenericPage

  def check_url=(page)
    puts(page)
  end

end

I create a new instance of my class, which I am calling in Cucumber

require_relative '../../../support/helper_methods'


class FindYourDealerPage
  include GenericPage


  def initialize(browser)
    @browser = browser
  end

def search_location=(location)
  @browser.text_field(:id, 'findDealerSearchField').set(location)
  @browser.send_keys :tab, :enter
end

Cucumber:

    Given /^I am on the find your dealer page$/ do

    @browser.goto 'www.google.com'
    @dealer.check_url('www.google.com')
    @dealer = FindYourDealerPage.new(@browser)
    end

    When /^I select a desired preference$/ do

    end

    Then /^my filtered selection should be submitted$/ do

    end

When this is run I get an error NoMethodError: undefined methodcheck_url' for nil:NilClass` where am I going wrong, forget what is in the method for the moment I just would like to know why I receive this error

4

1 回答 1

5

The problem, I think, is here

@dealer.check_url('www.google.com')
@dealer = FindYourDealerPage.new(@browser)

Notice how you call check_url before you assign @dealer... meaning that @dealer is still nil when you make the method call, and that's why you get a NoMethodError for nil:NilClass.

Also, you currently have def check_url=(page), but you call check_url(page). Depending on what you mean to happen here, you need to change the definition to def check_url(page) or change the call to @dealer.check_url = 'www.google.com' (I suspect the former is more appropriate).

于 2012-12-21T15:29:49.400 回答