我试图测试我的辅助函数,该函数返回cookie中的字符串集。测试看起来像这样:
context 'if the cookie does exist' do
it 'returns filled hash' do
request.cookies['history'] = '{\"1_2_2\":\"HAI\"}'
expect(history_terms_array).to eq('{\"1_2_2\":\"HAI\"}')
end
end
但由于某种原因,我不断收到以下错误:
Failure/Error: request.cookies['history'] = 'abc'
NoMethodError:
undefined method `cookies' for nil:NilClass
我忘记了什么吗?
答案 0 :(得分:0)
我不确定请求对象是否可用,而不是这样做,尝试使用存根
allow(request).to receive(:[]).with('history').and_return('{\"1_2_2\":\"HAI\"}')
expect(history_terms_array).to eq('{\"1_2_2\":\"HAI\"}')