[rspec-users] How to use expect_render?

Shaker flyeminent at hotmail.com
Mon Aug 13 05:21:01 EDT 2007


Dear Aslak and David:
    I have tried two possible ways to get expect_render work. However, they
all failed. My combinations are:
my controller spec
  describe MyController do
    before do
      #do nothing
    end
    it "should render the index partial" do
      controller.expect_render(:partial=>'index') #1st way
      MyController.expect_render(:partial=>'index') #2nd way
    end
  end

The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected
:render with ({:partial=>'index'}) once, but received it 0 times
The 2nd way gave me an error: undefined method 'expect_render'
Do I need to mock the controller or there are some mistakes I have made in
my spec?

Shaker wrote:
> 
> Hi:
>     I am a rspec beginner. I have scratched my head for the whole
> afternoon, trying to figure out a way of writing render expectation in
> controller spec. However, I failed. It kept telling me that the
> 'expect_render' was an undefined method. I have installed rspec 1.0.8 and
> rspec_on_rails as well. Below is the controller to be tested. 
>     
> Controller
>     def index
>       pre = Array.new
>       render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} 
>     end
> 
> My controller spec
>     before do
>       @controller = MyController.new
>     end
>     it "should render the index partial" do
>       @controller.expect_render(:partial=>'index', :layout=>false) #I
> don't know how to expect the :locals
>     end
> 
> As I mentioned, the spec failed , saying that "Undefined method
> 'expect_render' ". There might be some mistakes in my "before" block. Do I
> need to mock the controller or something else? Anyway, do any one know how
> to fix the problem? It will be even better if you guys could show me a
> piece of example code. 
>     Thanks!!
> 

-- 
View this message in context: http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224
Sent from the rspec-users mailing list archive at Nabble.com.



More information about the rspec-users mailing list