Trouble mocking on cucumber + rails
- by Lucas d. Prim
I'm having a lot of trouble trying to define a mock for a rails models on cucumber. It seems like the method is creating a bunch of message expectations and i keep getting errors like these:
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)
I haven't yet implemented the ProductCategory class and I just want it to return an ID and a 'name' attribute.
This is my step definition:
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
And this is my env.rb file:
$: << File.join(File.dirname(__FILE__),"..")
require 'spec\spec_helper
I am using RSPec 1.3.0, cucumber 0.6.3 and webrat 0.7.0
I've tried to use stubs as well but got some other errors instead...