Question

I have a step definition:

Then(/^I should see the total price of the products$/) do
  # assumes all existing products are in the cart
  total = Product.find(:all).inject { |sum, p| sum + p.price }
  page.find(".total").should have_content number_to_currency(total)
end

This blows up with undefined method 'number_to_currency' for #<Cucumber::Rails::World:0xbef8d18> (NoMethodError)

I could emulate the "total" by emulating the behaviour of the number_to_currency helper, but I'd rather re-use the helper from Rails, because in this step I am not interested in the formatting, just that the total is calculated and rendered.

How do I include the NumberHelper or any view helper in capybara for access from step definitions?

Was it helpful?

Solution

The way I include helper into my cucumber testing here:

  • You create a file world.rb (or any name you want) under support folder. In my world.rb I define like this:

    module Helper
    
       include ProjectHelper
       include ProductBacklogHelper
       include ApplicationHelper
       include Capybara::DSL
       include Prickle::Capybara 
    
    end #end Module  
    World(Helper)
    

You should include the helper file that has "number_to_currency" function in world.rb

I hope this will help you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top