[rspec-users] How to spec a Rails helper method
matt at mattwynne.net
Sun Nov 23 07:46:30 EST 2008
On 21 Nov 2008, at 18:18, Nick Hoffman wrote:
> I'm trying to write specs for a helper method that I'm creating, but
> my specs are failing to find the helper method
> # app/helpers/properties_helper.rb
> module PropertiesHelper
> def format_utilities(utilities)
> # spec/helpers/properties_helper_spec.rb
> require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
> describe PropertiesHelper do
> describe '#format_utilities' do
> it 'should format a utilities value' do
> format_utilities(nil).should == 'Unknown'
helper.format_utilities(nil).should == 'Unknown'
> The error that's occuring is:
> NoMethodError in 'PropertiesHelper#format_utilities should format a
> utilities value'
> undefined method `format_utilities' for
> lib/factories-and-workers/factory_builder.rb:36:in `method_missing'
> As far as I can tell, my specs match what was recommended back in
> March 2008 in this thread:
I don't know about that thread - I wasn't using RSpec at the time, but
certainly the way I've always done it is use HelperExampleGroup.helper
to call the helper module. This is backed up by the docs:
More information about the rspec-users