Rails Rspec错误 - 未定义的局部变量或#<rspec :: core :: examplegroup :: nested_3:0 ...> </rspec :: core :: examplegroup :: nested_3:0 ...>的方法

时间:2013-02-07 09:10:52

标签: ruby-on-rails rspec

我正在阅读迈克尔·哈特尔(Michael Hartl)铁道教程的第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

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

1 个答案:

答案 0 :(得分:3)

更改此行:

  

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

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