簡體   English   中英

RSpec:#的未定義方法“允許”

[英]RSpec: undefined method `allow' for #<RSpec::Core::ExampleGroup::Nested

我正在RSpec 2.12.2中編寫視圖規范。 我得到的錯誤是undefined method: allow 我在更高版本的RSpec中使用了類似的東西。 2.12.2中是否allow存在? 在此版本中,還有另一種方法來存根方法調用嗎?

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

直到2.14才引入Allow。 您可以使用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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM