只是我还是全局 RSpec 行为,当我命名我的 rails 模型范围:public
时,从这个模型初始化对象,然后存根这个对象 Rspec 失败
class DocumentName < ActiveRecord::Base
scope :public, lambda{where( public: true) } #line 3
end
没什么特别的,Rails 应用程序有效
DocumentName.public # => [ #DN, #DN, #DN... ]
# SELECT `document_names`.* FROM `document_names` WHERE `document_names`.`public` = 1
但是 RSpec 失败了
describe DocumentName do
let(:resource){DocumentName.new}
it do
resource.stub(:name).and_return('foo') #line 16
resource.save.should be true
end
end
Failure/Error: resource.stub(:name).and_return('foo')
ArgumentError:
wrong number of arguments (1 for 0)
# ./app/models/document_name.rb:3:in `block in <class:DocumentName>'
# ./spec/models/document_name_spec.rb:16:in `block (2 levels) in <top (required)>'
...而且最有趣的是,在这种情况下,我没有在那个范围内做任何事情。
但是,如果我将此范围命名为:public
例如:are_public
:
class DocumentName < ActiveRecord::Base
scope :are_public, lambda{where( public: true) }
end
...一切都通过 O_O
Rails 3.2.11 (but same thing on any 3.2.x)
Ruby ruby-2.0.0-rc1 ( but same for any ruby-1.9.3)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
rspec-mocks (2.12.1)
rspec-rails (2.12.2)