public
Description: Rails plugin with helpers to test your app using test/spec.
Homepage: http://agilewebdevelopment.com/plugins/test_spec_on_rails
Clone URL: git://github.com/pelargir/test_spec_on_rails.git
Search Repo:
added should.render for testing template rendering
Matthew Bass (author)
Sat Jun 28 18:20:44 -0700 2008
commit  6e648ea2476a340d812ddd05ce011431761fe0f7
tree    91cf43a59963c02b14ff0fb15d49c9fa12ea3283
parent  26992049d0330a52400d1f1d60de556c939813f5
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+06/28/08 - Added should.render for testing template rendering [Matthew Bass]
0
+
0
 05/15/08 - First pass at overriding generators to produce specs [Matthew Bass]
0
 
0
 03/18/08 - it_should_validate_presence_of helper added [Matthew Bass]
...
15
16
17
 
18
19
20
...
15
16
17
18
19
20
21
0
@@ -15,6 +15,7 @@ end
0
   test_layout
0
   
0
   should_redirect
0
+ should_render
0
   should_route
0
   should_select
0
   should_validate

Comments

  • jasonrudolph Sun Jun 29 18:56:54 -0700 2008 at lib/test/spec/rails/should_render.rb L0

    I don’t think this assertion should assume that the response code is :success.

    Consider the case when I want to assert that I render the correct template for a “page not found” scenario. In traditional test/unit style, that would look like…


    def test_should_render_not_found_for_nonexistent_product
    get :show, :id => -1
    assert_response :not_found
    assert_equal "/shared/404", @response.rendered_file
    end


    In test/spec/rails, I tackle this as follows…


    status.should.be :not_found
    template.should.be "/shared/404"
    <pre>

    I like the idea of having a being able to say <code>should.render "/shared/404"</code>, but I wouldn't want to be locked into using only the <code>:success</code> code. If <code>#render</code> looks at the status code at all, I'd recommend defaulting to :success but allow the caller to pass in an alternate status code.

    What do you think?