How can I include application_helper.rb in my tests so that I can use any bespoke helper methods?
require 'rubygems' require 'action_view' require 'action_view/helpers' require './app/helpers/application_helper' include ApplicationHelper
Depending on what you put in your helper, you might be able to get away with less than that. Much less.
I was simply experimenting with the number_to_currency() method which pops up a lot at the beginning of the depot app. Just to play around, in the application_helper I added:
def currency(number) number_to_currency(number, unit: "£") end
so that I could change the units used in a single place.
Now when I run my tests I get told that currency method is not defined.
Is your ‘long answer’ the simplest way for this?
currency not defined means that you have defined currency in a module that you haven’t included in your current scope, so the include statement addresses this. The next problem you will find is that number_to_currency is not defined, and that’s what the rest of the lines help with.
For more information, scan ahead to section 24.2. This information is at the bottom of that section.
Thanks for your help Sam
I ran in this problem in Task J, Playtime for Activity 2 when running functional and integration tests.
The hint for Activity 2 is to use a helper. I have put the helper to the application_helper.rb
Maybe a link to your answer would be helpfull for others that run into that problem.
Thanks for the post!