small medium large xlarge

12 Nov 2011, 15:37
Adam Tait (8 posts)

How can I include application_helper.rb in my tests so that I can use any bespoke helper methods?

12 Nov 2011, 19:31
Sam Ruby (634 posts)

Long answer:

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.

16 Nov 2011, 21:31
Adam Tait (8 posts)

Thanks Sam.

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: "£")

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?

Thanks again.

16 Nov 2011, 22:05
Sam Ruby (634 posts)

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.

17 Nov 2011, 21:05
Adam Tait (8 posts)

Thanks for your help Sam

22 Dec 2012, 21:19
Pierre Sugar (57 posts)

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!

You must be logged in to comment