gpt4 book ai didi

ruby-on-rails - Rails Rspec 错误 - # 的未定义局部变量或方法

转载 作者:行者123 更新时间:2023-12-04 05:12:23 31 4
gpt4 key购买 nike

我正在阅读 Michael Hartl 的 railstutorial 的第 11 章,但遇到了一些 rspec 错误。

rspec error

我不太确定错误消息是什么意思。

以防万一,这是我的规范代码。

  let(:follower) {FactoryGirl.create(:user)}
let(:followed) {FactoryGirl.create(:user)}
let(:relationship) {follower.relationships.build(followed_id: followed_id)}

subject {relationship}

it {should be_valid}

describe "accessible attributes" do
it "should not allow access to follower_id" do
expect do
Relationship.new(follower_id: follower_id)
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
end
end

任何帮助将不胜感激。谢谢!

最佳答案

改变这一行:

let(:relationship) {follower.relationships.build(followed_id: followed_id)}




let(:relationship) {follower.relationships.build(followed_id: followed.id)}

关于ruby-on-rails - Rails Rspec 错误 - #<RSpec::Core::ExampleGroup::Nested_3:0...> 的未定义局部变量或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747361/

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