I have a Rails 3 helper that returns code based on parameters and request.headers. I tried to mock them, but failed. My last attempt:
require 'spec_helper' describe ApplicationHelper, "#banner" do before do @b728 = Factory :banner, :code => '<div style="width: 728px">:(clickref)</div>', :width => 728, :height => 90 @b160 = Factory :banner, :code => '<div style="width: 160px">:(clickref)</div>', :width => 160, :height => 600 Factory :ad_sense_channel, :key => "country", :value => nil, :ad_sense_id => 1 Factory :ad_sense_channel, :key => "country", :value => "de", :ad_sense_id => 2
I still throw an exception:
NameError: undefined local variable or method `params' for # # ./app/helpers/application_helper.rb:7:in `banner'
Solution: thanks to zetetic, my specification is now read as follows:
controller.params = {:controller => "dictionaries", :action => "index"} controller.request.stub(:headers) { {"Accept-Language" => "de-DE, kr"} } @detected_location = DetectedLocation.new("193.99.144.80") helper.banner(728, 90, "left").should eq('11+2+21+31+41')
source share