Guest User

Untitled

a guest
Feb 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. ## Controller
  2.  
  3. class ClientsController < ApplicationController
  4. def new
  5. @client = Client.new
  6. end
  7. end
  8.  
  9. ## Unit test
  10.  
  11. require File.dirname(__FILE__) + '/../test_helper'
  12. require_dependency 'clients_controller'
  13.  
  14. # Re-raise errors caught by the controller.
  15. class ClientsController; def rescue_action(e) raise e end; end
  16.  
  17. context "new client" do
  18. def setup
  19. @controller = ClientsController.new
  20. @session = ActionController::TestSession.new
  21. @request = ActionController::TestRequest.new
  22. @response = ActionController::TestResponse.new
  23. @controller.stubs(:logged_in?).returns(true)
  24. Client.expects(:new).returns(stub)
  25. end
  26.  
  27. specify "should render new.rhtml" do
  28. # First try...
  29. # @response.template.expects(:render_file)
  30. # Failure: Cannot replace render_file because it is not defined in .
  31. # Failure: :render_file('** any **'): expected calls: 1, actual calls: 0
  32.  
  33. # Second try...
  34. ActionView::Base.any_instance.expects(:render_file).with('clients/new', true, {})
  35. # Failure: Unexpected message :render_file('clients/new', true, {}) sent to #<Mocha::Mock: 30432780>
  36. # Failute: :render_file('clients/new', true, {}): expected calls: 1, actual calls: 0
  37.  
  38. get :new
  39. end
  40. end
Add Comment
Please, Sign In to add comment