[rspec-users] How to use expect_render?

Shaker flyeminent at hotmail.com
Mon Aug 13 04:15:46 EDT 2007


Hello, Aslak:
    I know we could do template.expect_render somehow, although I haven't
tried that out. But the rspec developer said that we could now actually use
controller.expect_render in controller specs, which caused me confused. You
may want to have a look at this:
http://rspec.rubyforge.org/documentation/rails/writing/controllers.html
writing controller spec 
    Thanks, regards. 

aslak hellesoy wrote:
> 
> On 8/13/07, Shaker <flyeminent at hotmail.com> 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!!
> 
> Have you looked here?
> 
> http://rspec.rubyforge.org/documentation/rails/writing/views.html
> 
> (you must use template.expect_render)
> Or perhaps you're looking for response.should
> render_template("path/to/template/for/action")
> 
> HTH,
> Aslak
> 
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894
>> Sent from the rspec-users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> 
> 

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



More information about the rspec-users mailing list