gpt4 book ai didi

ruby-on-rails - RSpec:#
转载 作者:行者123 更新时间:2023-12-04 03:54:13 24 4
gpt4 key购买 nike

我正在 RSpec 2.12.2 中编写 View 规范。我收到的错误是 undefined method: allow。我在 RSpec 的更高版本中使用了类似的东西。 allow 是否在 2.12.2 中不存在?在这个版本中是否有另一种方法来 stub 方法调用?

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)

关于ruby-on-rails - RSpec:#<RSpec::Core::ExampleGroup::Nested 的未定义方法 `allow',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34300025/

24 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com