Reputation: 16627
I am trying to test the render method in a controller with RSpec (2.x). Here the code in my controller:
respond_to do |format| format.html # index.html.erb format.json { render :json => @entities, :include => :properties, :overview => options[:overview] } end
And here the test I try in my spec file:
controller.should_receive(:render).with( hash_including(:overview => true) )
The problem is that RSpec tells me that no arguments are provided for render ("got: (no args)"). Not even the :json one. How do I stub the render method correctly?
Upvotes: 1
Views: 4163
Reputation: 5286
If you want to test your render :json
, just check that the response does contain a JSON string.
Simplified example: response.body.should == @object.to_json
If you just want to stub render method use controller.stub!(:render)
Upvotes: 4