我正在RSpec 2.12.2中编写一个视图规范。我得到的错误是undefined method: allow
。我在RSpec的后续版本中使用了类似的东西。allow
是否不存在于2.12.2中?在这个版本中,是否有其他方法可以存根方法调用?
require 'spec_helper'
describe "user_achievements/index.html.haml" do
let(:application) { double }
let(:user) { double }
before do
allow(view).to receive_message_chain(:user, :registered?).and_return(true)
render
end
it "includes a table for user achievements" do
expect(rendered).to have_css(".data-table")
end
end
Allow直到2.14才推出。您可以使用obj.stub和stub_chain
# specify a return value
obj.stub(:message) { :value }
obj.stub(:message => :value)
obj.stub(:message).and_return(:value)
subject.stub_chain(:one, :two, :three).and_return(:four)