[rspec-devel] [ rspec-Bugs-6889 ] Mock expectations not satisfied by code in view

noreply at rubyforge.org noreply at rubyforge.org
Sun Nov 26 07:26:49 EST 2006


Bugs item #6889, was opened at 2006-11-26 06:21
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6889&group_id=797

Category: mock module
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Pat Maddox (pergesu)
Assigned to: Nobody (None)
Summary: Mock expectations not satisfied by code in view

Initial Comment:
Consider this method:

def create_user
  @u = mock("user")
  @u.should_receive(:people).and_return([OpenStruct.new(:name => 'Justin'), OpenStruct.new(:name => 'BJ')])
  User.should_receive(:find_by_login).with('pat').and_return(@u)
end

Now the setup for this spec is:
setup do
  create_user
  get :show, :id => 'pat'
end

Controller code is:
def show
  @user = User.find_by_login params[:id]
end

And then the view:
<% @user.people.each do |p| %>
  <%= h p.name %>
<% end %>

The mock object @u expects the people method to be called.  It is called in the view.  However when I run the spec, I get "Mock 'user' expected :people once, but received it 0 times"

Is this expected behavior?  If so, why?  I haven't found anything in the list archives or previous bug reports.

----------------------------------------------------------------------

>Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-11-26 07:26

Message:
If your spec is a controller spec AND you haven't explicitly enabled view integration (using integrate_views) then RSpec will not invoke the view at all (which would explain your failure). This is a feature. For more info see

http://rspec.rubyforge.org/documentation/rails/writing/controllers.html
http://rspec.rubyforge.org/documentation/rails/writing/views.html



----------------------------------------------------------------------

Comment By: Aslak Hellesøy (aslak_hellesoy)
Date: 2006-11-26 07:22

Message:
* What versions/revisions of RSpec/Rails are you using?
* Is this a controller spec or a view spec. Are you using integrated views (http://rspec.rubyforge.org/documentation/rails/writing/controllers.html)? 
* Can you help us reproduce this failure by modifying the demo app in rspec_on_rails and send us a patch file?


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6889&group_id=797


More information about the rspec-devel mailing list