我在尝试为黄瓜铁轨模型定义一个模拟方面遇到了很多麻烦。这似乎是方法创造了一堆的消息的期望,我不断收到错误,像这样的:在黄瓜+铁轨上嘲笑问题
Given I have only a product named "Sushi de Pato" # features/step_definitions/product_
steps.rb:19
unexpected invocation: #<Mock:ProductCategory_1001>.__mock_proxy()
unsatisfied expectations:
- expected exactly once, not yet invoked: #<Mock:ProductCategory_1001>.errors(any_pa
rameters)
- expected exactly once, not yet invoked: #<Mock:ProductCategory_1001>.id(any_parame
ters)
- expected exactly once, not yet invoked: #<Mock:ProductCategory_1001>.to_param(any_
parameters)
- expected exactly once, not yet invoked: #<Mock:ProductCategory_1001>.new_record?(a
ny_parameters)
- expected exactly once, not yet invoked: #<Mock:ProductCategory_1001>.destroyed?(an
y_parameters)
satisfied expectations:
- allowed any number of times, not yet invoked: #<Mock:errors>.count(any_parameters)
(Mocha::ExpectationError)
我还没有实现的产品分类的类,我只是希望它返回一个ID和一个“名称”属性。
这是我的步骤定义:
Given /^I have only a product named "([^\"]*)"$/ do |name|
@product = Product.create!(:name => name, :description => 'Foo', :price => 100, :points => 100, :category => mock_model(ProductCategory))
end
这是我env.rb文件:
$: << File.join(File.dirname(__FILE__),"..")
require 'spec\spec_helper
我使用RSPEC 1.3.0,0.6.3黄瓜和webrat 0.7.0
我试着使用存根很好,但有一些其他的错误,而不是...
我认为你是绝对正确的!在阅读了很多关于黄瓜试图解决这个问题的东西之后,我得出了这样一个结论,即黄瓜应该更多地作为一个集成测试,因此需要我描述的每个东西都要实施。我通过创建ProductCategory模型规范然后实现它来解决它。我认为这是有道理的,因为Product和ProductCategory紧密相关。 非常感谢你! – 2010-03-20 20:51:40