【问题标题】:Rspec + Shoulda + FactoryGirl = undefined method `reflect_on_association'Rspec + Shoulda + FactoryGirl = 未定义方法 `reflect_on_association'
【发布时间】:2010-02-24 03:47:05
【问题描述】:

我有 Rspec + Shoulda + FactoryGirl,在尝试调用 Shoulda 的 have_many 或 belongs_to 方法时收到以下错误。 “验证”组中使用的所有 Shoulda 方法都可以正常工作:

>   NoMethodError in 'A Project
> associations should When you call a
> matcher in an example without a
> String, like this:
> 
>   specify { object.should matcher }
> 
>   or this:
> 
>   it { should matcher }
> 
>   RSpec expects the matcher to have a
> #description method. You should either   add a String to the example this
> matcher is being used in, or give it a
> description method. Then you won't
> have to suffer this lengthy warning
> again.   '   undefined method
> `reflect_on_association' for
> #<Project:0x34d8624>   /vendor/plugins/active_matchers/lib/matchers/association_matcher.rb:37:in
> `confirm_association'  
> /vendor/plugins/active_matchers/lib/matchers/association_matcher.rb:36:in
> `each'  
> /vendor/plugins/active_matchers/lib/matchers/association_matcher.rb:36:in
> `confirm_association'  
> /vendor/plugins/active_matchers/lib/matchers/association_matcher.rb:11:in
> `matches?'  
> ./spec/models/project_spec.rb:7:

提前致谢

spec/spec_helper.rb

require 'shoulda'

spec/models/project_spec.rb

require File.dirname(__FILE__) + '/../spec_helper'

describe "A Project" do
  describe "associations" do

    subject { Factory(:project) }

    it { should have_many(:tasks) }
    it { should belong_to(:project_status) }
  end

  describe "validations" do
    subject { Factory(:project) }

    it { should validate_presence_of(:name) }

    it { should validate_uniqueness_of(:name).case_insensitive }

    it { should allow_mass_assignment_of(:name) }
  end
end

【问题讨论】:

    标签: ruby-on-rails rspec shoulda factory-bot


    【解决方案1】:

    感谢 David C. 指出应该显而易见的内容。我有一个多余的 active_matchers 插件,它与 shoulda 冲突。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2016-08-22
    • 1970-01-01
    相关资源
    最近更新 更多