我是新來的紅寶石在軌道上。當我在comment_spec.rb rspec的運行我得到一個未定義的方法錯誤未定義的局部變量或方法`請求'
1) after_save calls 'Post#update_rank' after save
Failure/Error: request.env["HTTP_REFERER"] = '/'
NameError:
undefined local variable or method `request' for #<RSpec::ExampleGroups::AfterSave:0x007fa866ead8d0>
# ./spec/models/vote_spec.rb:45:in `block (2 levels) in <top (required)>'
這是我的規格:
require 'rails_helper'
describe Vote do
....
describe 'after_save' do
it "calls 'Post#update_rank' after save" do
request.env["HTTP_REFERER"] = '/'
@user = create(:user)
@post = create(:post, user: @user)
sign_in @user
vote = Vote.new(value:1, post: post)
expect(post). to receive(:update_rank)
vote.save
end
end
任何幫助,你將不得不將不勝感激......
你的模型規格都無關的要求,甚至在登錄用戶是什麼。你想要做什麼? – sevenseacat 2014-09-27 15:08:30