Topic: undefined method params in helper spec

I am testing a block helper called filterForAdmin and i get the following error

undefined local variable or method `params' for #<ApplicationHelper::FilterForAdmin:0x102f539f0>

This is my spec

it "should be equal with ...." do
    helper.stub!(:params).and_return {}
    eval_erb(%(
      <% filter_for_admin categories_path do |field| %>
        <% field.li_filter "active", categories_path(:filter=>"active") %>
      <% end %>
    )).should match_html('<ul id="admin_filters"><li class="selected"><a href="/categories">All</a>...etc'

and where the error occures:

module ApplicationHelper
    class FilterForAdmin < BlockHelpers::Base
    def initialize(path)
      @path = path
    end
    
    def display(body)
      content_tag(:ul, 
        content_tag(:li, link_to("All", @path), :class => "#{"selected" unless params[:filter]}") +
        body, 
        :id => "admin_filters")      
    end
end
end

the spec doenst recognise the params variable. Does somebody know what i am doing wrong?

Do i need to change the stubbing method?

helper.stub!(:params).and_return {}

Thanks in advance

michael

Re: undefined method params in helper spec

I'm guessing you're using this plugin: http://github.com/markevans/block_helpers

When this line in your display method is called:

content_tag(:li, link_to("All", @path), :class => "#{"selected" unless params[:filter]}")

Ruby will look for a method called params in the FilterForAdmin or BlockHelpers::Base classes or a local variable named params. None of these exist so you get an error. Instead you'll have to pass your filter param in to initialize:

module ApplicationHelper
    class FilterForAdmin < BlockHelpers::Base
    def initialize(path, filter)
      @path = path
      @filter = filter
    end
    
    def display(body)
      content_tag(:ul, 
        content_tag(:li, link_to("All", @path), :class => "#{"selected" unless @filter}") +
        body, 
        :id => "admin_filters")      
    end
end
end
Rob Anderton
TheWebFellas