在rspec帮助器测试中设置request.fullpath

时间:2013-05-23 00:01:14

标签: ruby-on-rails ruby rspec

唯一可行的是做这样的事情

let(:request){ stub('request', :fullpath => '/path/to/place?arg=value') }
it 'blah blah' do
...
end

问题在于,我想在测试过程中更改此值,但似乎没有一种简单的方法可以做到这一点

具体而言

helper.request.path = '/search?search_type=question'

不起作用。我得到了

undefined method `fullpath=' for #<ActionController::TestRequest:0x007fe203e47d88>

PS:是的,我检查过Rails: test a helper that needs access to the Rails environment (e.g. request.fullpath),除了let指令似乎没有任何作用

1 个答案:

答案 0 :(得分:2)

证明你必须做...(使用摩卡)

helper.request.stubs(:fullpath).returns('/search')

并调用辅助方法来测试它

helper.method.should == true
相关问题