【发布时间】:2010-03-19 20:03:16
【问题描述】:
我在尝试为黄瓜上的导轨模型定义模拟时遇到了很多麻烦。似乎该方法正在创建一堆消息期望,并且我不断收到以下错误:
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)
我还没有实现 ProductCategory 类,我只是希望它返回一个 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
我也尝试过使用存根,但出现了一些其他错误...
【问题讨论】:
标签: ruby-on-rails mocking rspec cucumber bdd