【发布时间】:2009-11-16 21:13:23
【问题描述】:
我知道这一定很愚蠢,但在我的一个示例中我不断收到以下错误:
undefined method `new' for #<Class:0x211d274>
我创建了一个简单的示例来显示错误:
describe LateCharge do
before :each do
@membership = Membership.new
@location = mock_model(Location, :late_payment_rate => 10)
end
it "should initialize" do
LateCharge.respond_to?('new').should == true
@charge = LateCharge.new(@membership, @location)
end
end
奇怪的是,当我自己运行示例时,它通过了。当我使用所有示例运行它时,它会失败并出现以下错误:
NoMethodError in 'LateCharge should initialize'
undefined method `new' for #<Class:0x211d274>
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1964:in `method_missing_without_paginate'
/Users/l33/.gem/ruby/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:in `method_missing'
./spec/models/late_charge_spec.rb:15:
上线失败:@charge = LateCharge.new(@membership, @location)
在运行时或从控制台实例化 LateCharge 对象没有任何问题。
有人有什么想法吗?
【问题讨论】:
标签: ruby-on-rails activerecord rspec