[rspec-users] How to spec a Rails helper method

Ryan Briones ryan.briones at brionesandco.com
Sun Nov 23 13:49:26 EST 2008


I'm not sure what version it was, but Rails helper modules are no longer
included implicitly in helper specs. [1]

You should rewrite your spec as:

describe PropertiesHelper do
 describe '#format_utilities' do
   it 'should format a utilities value' do
     helper.format_utilities(nil).should == 'Unknown'
   end
 end
end

or

describe PropertiesHelper do
 include PropertiesHelper
 describe '#format_utilities' do
   it 'should format a utilities value' do
     format_utilities(nil).should == 'Unknown'
   end
 end
end

[1]
http://blog.davidchelimsky.net/2008/5/29/rspec-waving-bye-bye-to-implicit-module-inclusion

On Fri, Nov 21, 2008 at 1:18 PM, Nick Hoffman <nick at deadorange.com> 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)
>  end
> end
>
> # 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'
>    end
>  end
> end
>
> The error that's occuring is:
>
> NoMethodError in 'PropertiesHelper#format_utilities should format a
> utilities value'
> undefined method `format_utilities' for
> #<Spec::Rails::Example::HelperExampleGroup::Subclass_1::Subclass_1:0x22a121c>
> /Users/nick/src/housing-rentals/vendor/plugins/factories-and-workers/lib/factories-and-workers/factory_builder.rb:36:in
> `method_missing'
> ./spec/helpers/properties_helper_spec.rb:7:
> script/spec:4:
>
> As far as I can tell, my specs match what was recommended back in March
> 2008 in this thread:
>  http://www.ruby-forum.com/topic/145723
>
> Any suggestions?
> -Nick
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
Ryan Carmelo Briones
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081123/dc5cc062/attachment.html>


More information about the rspec-users mailing list