2010-02-24 92 views
2

我有Rspec + Shoulda + FactoryGirl,并且在尝试调用Shoulda的have_many或belong_to方法时收到以下错误。在 “验证” 组,做工精细使用的所有早该方法:Rspec + Shoulda + FactoryGirl =未定义的方法`reflect_on_association'

> 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_helper.rb

require 'shoulda' 

规格/型号/ 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 

回答

-2

感谢David C.指出了本该显而易见的事情。我有一个与shoulda冲突的冗余active_matchers插件。

+3

谁是David C?他指出了什么? – Esko 2010-02-25 13:08:34

+0

他可能是在谈论这个https://www.ruby-forum.com/topic/204841我猜 – jipiboily 2015-04-02 23:13:24

相关问题