【问题标题】:Remarkable active record association显着的活动记录关联
【发布时间】:2012-11-18 08:25:36
【问题描述】:

我正在使用 gem Remarkable activerecord 进行关联。我已经安装了卓越和卓越的 activerecrod 两个 gem。我已经在我的 Gemfile 中添加了两个 gem。我在 spec_helper.rb 中添加了“remarkable_activerecord”。

               describe Authentication do
                 FactoryGirl.build(:authentication).should belong_to(:user) 
                end

我得到了错误: 身份验证 失败/错误:它 { 应该属于_to(:user) } 无方法错误: 未定义的方法 `belong_to' for #

现在应该怎么做..??在此先感谢

【问题讨论】:

    标签: ruby-on-rails rspec gem rspec-rails


    【解决方案1】:

    您需要定义 it 所指的内容,方法是在测试示例的正上方包含 subject { something }

    【讨论】:

      【解决方案2】:

      您缺少一些 RSpec 语法。为了使用“应该”断言,它必须在“它”或“指定”块内。有许多不同的方法可以做到这一点,但这里有一种简洁的方法:

      describe Authentication do
        subject { FactoryGirl.build(:authentication) }
        it { should belong_to(:user) }
      end
      

      【讨论】:

      • 感谢比灵顿。我以前试过。它给出了相同的结果。
      • 您是否正在使用包含这些帮助器的 gem,例如 shoulda
      猜你喜欢
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多