4

似乎唯一可行的就是做这样的事情

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 need to access the Rails environment (eg request.fullpath),除了 let 指令似乎没有任何作用

4

1 回答 1

3

原来你必须做......(使用摩卡咖啡)

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

并调用辅助方法来测试它

helper.method.should == true
于 2013-05-23T22:42:12.377 回答