Commit eef1ff210eef5e2f98a2e2000a3fed826368fe1e
1 parent
7a7e6d8f
Exists in
master
and in
1 other branch
updated blitz
Showing
2 changed files
with
40 additions
and
18 deletions
Show diff stats
vendor/plugins/blitz/features/step_definitions/functional_test_steps.rb
| @@ -46,28 +46,38 @@ end | @@ -46,28 +46,38 @@ end | ||
| 46 | 46 | ||
| 47 | Then /^a standard "show" functional test for "posts" should be generated$/ do | 47 | Then /^a standard "show" functional test for "posts" should be generated$/ do |
| 48 | assert_generated_file("test/functional/posts_controller_test.rb") do | 48 | assert_generated_file("test/functional/posts_controller_test.rb") do |
| 49 | - " context 'GET to show for existing post' do\n" << | ||
| 50 | - " setup do\n" << | ||
| 51 | - " @post = Factory(:post)\n" << | ||
| 52 | - " get :show, :id => @post.to_param\n" << | ||
| 53 | - " end\n\n" << | ||
| 54 | - " should_assign_to :post, :equals => '@post'\n" << | ||
| 55 | - " should_render_template :show\n" << | ||
| 56 | - " should_respond_with :success\n" << | 49 | + " context 'GET to show for existing post' do\n" << |
| 50 | + " setup do\n" << | ||
| 51 | + " @post = Factory(:post)\n" << | ||
| 52 | + " Post.stubs(:find).returns(@post)\n" << | ||
| 53 | + " get :show, :id => @post.to_param\n" << | ||
| 54 | + " end\n\n" << | ||
| 55 | + " should 'find post' do\n" << | ||
| 56 | + " assert_received(Post, :find) do |expects|\n" << | ||
| 57 | + " expects.with(@post.id)\n" << | ||
| 58 | + " end\n" << | ||
| 59 | + " end\n\n" << | ||
| 60 | + " should_render_template :show\n" << | ||
| 61 | + " should_respond_with :success\n" << | ||
| 57 | " end" | 62 | " end" |
| 58 | end | 63 | end |
| 59 | end | 64 | end |
| 60 | 65 | ||
| 61 | Then /^a standard "edit" functional test for "posts" should be generated$/ do | 66 | Then /^a standard "edit" functional test for "posts" should be generated$/ do |
| 62 | assert_generated_file("test/functional/posts_controller_test.rb") do | 67 | assert_generated_file("test/functional/posts_controller_test.rb") do |
| 63 | - " context 'GET to edit for existing post' do\n" << | ||
| 64 | - " setup do\n" << | ||
| 65 | - " @post = Factory(:post)\n" << | ||
| 66 | - " get :edit, :id => @post.to_param\n" << | ||
| 67 | - " end\n\n" << | ||
| 68 | - " should_assign_to(:post) { '@post' }\n" << | ||
| 69 | - " should_render_template :edit\n" << | ||
| 70 | - " should_respond_with :success\n" << | 68 | + " context 'GET to edit for existing post' do\n" << |
| 69 | + " setup do\n" << | ||
| 70 | + " @post = Factory(:post)\n" << | ||
| 71 | + " Post.stubs(:find).returns(@post)\n" << | ||
| 72 | + " get :edit, :id => @post.to_param\n" << | ||
| 73 | + " end\n\n" << | ||
| 74 | + " should 'find post' do\n" << | ||
| 75 | + " assert_received(Post, :find) do |expects|\n" << | ||
| 76 | + " expects.with(@post.id)\n" << | ||
| 77 | + " end\n" << | ||
| 78 | + " end\n\n" << | ||
| 79 | + " should_render_template :edit\n" << | ||
| 80 | + " should_respond_with :success\n" << | ||
| 71 | " end" | 81 | " end" |
| 72 | end | 82 | end |
| 73 | end | 83 | end |
vendor/plugins/blitz/generators/functional_test/templates/functional_test.rb
| @@ -35,10 +35,16 @@ class <%= class_name %>ControllerTest < ActionController::TestCase | @@ -35,10 +35,16 @@ class <%= class_name %>ControllerTest < ActionController::TestCase | ||
| 35 | context 'GET to show for existing <%= resource %>' do | 35 | context 'GET to show for existing <%= resource %>' do |
| 36 | setup do | 36 | setup do |
| 37 | @<%= resource %> = Factory(:<%= resource %>) | 37 | @<%= resource %> = Factory(:<%= resource %>) |
| 38 | + <%= resource_class %>.stubs(:find).returns(@<%= resource %>) | ||
| 38 | get :show, :id => @<%= resource %>.to_param | 39 | get :show, :id => @<%= resource %>.to_param |
| 39 | end | 40 | end |
| 40 | 41 | ||
| 41 | - should_assign_to :<%= resource %>, :equals => '@<%= resource %>' | 42 | + should 'find <%= resource %>' do |
| 43 | + assert_received(<%= resource_class %>, :find) do |expects| | ||
| 44 | + expects.with(@<%= resource %>.id) | ||
| 45 | + end | ||
| 46 | + end | ||
| 47 | + | ||
| 42 | should_render_template :show | 48 | should_render_template :show |
| 43 | should_respond_with :success | 49 | should_respond_with :success |
| 44 | end | 50 | end |
| @@ -48,10 +54,16 @@ class <%= class_name %>ControllerTest < ActionController::TestCase | @@ -48,10 +54,16 @@ class <%= class_name %>ControllerTest < ActionController::TestCase | ||
| 48 | context 'GET to edit for existing <%= resource %>' do | 54 | context 'GET to edit for existing <%= resource %>' do |
| 49 | setup do | 55 | setup do |
| 50 | @<%= resource %> = Factory(:<%= resource %>) | 56 | @<%= resource %> = Factory(:<%= resource %>) |
| 57 | + <%= resource_class %>.stubs(:find).returns(@<%= resource %>) | ||
| 51 | get :edit, :id => @<%= resource %>.to_param | 58 | get :edit, :id => @<%= resource %>.to_param |
| 52 | end | 59 | end |
| 53 | 60 | ||
| 54 | - should_assign_to(:<%= resource %>( { @<%= resource %> } | 61 | + should 'find <%= resource %>' do |
| 62 | + assert_received(<%= resource_class %>, :find) do |expects| | ||
| 63 | + expects.with(@<%= resource %>.id) | ||
| 64 | + end | ||
| 65 | + end | ||
| 66 | + | ||
| 55 | should_render_template :edit | 67 | should_render_template :edit |
| 56 | should_respond_with :success | 68 | should_respond_with :success |
| 57 | end | 69 | end |