0

I have created a module with a method

module Adding_preferences
  def desired_preferences            
    @preference = %w(motabilitySpecialist newCars bodyshop filter8 filter7).each do |selection|            
      @browser.label(:for,  selection ).click    
    end
  end
end

I have included this module into a class:

class Pages
  include Adding_preferences

  attr_accessor :browser, :preference

  def initialize
    @browser = Watir::Browser.new :ff
  end
end

World do
  Pages.new
end

I am calling this method in a Cucumber scenario

When /^I select a desired preference$/ do
  desired_preferences
end

But at runtime I receive an error, "NameError: undefined local variable or method `desired_preferences'". Where am i going wrong?

M4N
  • 94,805
  • 45
  • 217
  • 260
user1875703
  • 159
  • 2
  • 5
  • 14

2 Answers2

1

When you include a module to a class you can use this method in the instance methods of this class. You cant call the included method in a View that displays the data from the model that includes the module. For me it looks like you just dont use the desired_preferences method in an instance method.

Please show us the peace of code you try to call the method if this still doesnt help you out.

// The naming of the Module is not conventional. You should call it module AddingPreferences isntead ofmodule Adding_preferences and the file should be named adding_preferences.rb then try to include AddingPreferences

davidb
  • 8,884
  • 4
  • 36
  • 72
0

It's a good idea for you to spend some time getting more familiar with Ruby's Class/Module/Object/Method inheritance model, because the way you're structuring your code there is a little bit messy.

However, a simple thing to try (and I'm not going to guarantee that it will work flawlessly) is the following modifications:

Assign your instantiated Pages class to a class instance variable:

World do
  @page = Pages.new
end

...and then use that instance variable in your step definition...

When /^I select a desired preference$/ do
  @page.desired_preferences
end

I hope that helps!

Abe Heward
  • 515
  • 3
  • 16