在测试我的辅助方法时,我不知道如何测试是否设置了 cookie。
假设的辅助方法:
def my_helper(k,v)
cookies[k] = v
end
测试:
it 'should set cookies' do
helper.my_helper("foo", "bar")
helper.cookies["foo"].should == "bar" #nil
helper.response.cookies["foo"].should == "bar" #nil
end
有人知道怎么做吗?
最佳答案
如果您愿意,用一个简单的 rspec 模拟代替 CookieJar 可以:
helper.stubs(:cookies => cookies = mock)
cookies.expects(:[]=).with('foo', 'bar')
helper.my_helper('foo', 'bar')
关于ruby-on-rails - 如何在帮助程序规范中访问 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11659244/