################################################ Units Controller ################################################ class UnitsController < ApplicationController before_filter :login_required def index @units = Unit.all end def show @unit = Unit.find(params[:id]) end def new @unit = Unit.new end def create @unit = Unit.new(params[:unit]) if @unit.save redirect_to @unit, :notice => "Successfully created unit." else render :action => 'new' end end def edit @unit = Unit.find(params[:id]) end def update @unit = Unit.find(params[:id]) if @unit.update_attributes(params[:unit]) redirect_to @unit, :notice => "Successfully updated unit." else render :action => 'edit' end end def destroy @unit = Unit.find(params[:id]) @unit.destroy redirect_to units_url, :notice => "Successfully destroyed unit." end end ################################################ UnitsControllerTest ################################################ require 'test_helper' class UnitsControllerTest < ActionController::TestCase def test_index get :index assert_template 'index' end def test_show get :show, :id => Unit.first assert_template 'show' end def test_new login_as :foo get :new assert_template 'new' end def test_create_invalid Unit.any_instance.stubs(:valid?).returns(false) post :create assert_template 'new' end def test_create_valid Unit.any_instance.stubs(:valid?).returns(true) post :create assert_redirected_to unit_url(assigns(:unit)) end def test_edit get :edit, :id => Unit.first assert_template 'edit' end def test_update_invalid Unit.any_instance.stubs(:valid?).returns(false) put :update, :id => Unit.first assert_template 'edit' end def test_update_valid Unit.any_instance.stubs(:valid?).returns(true) put :update, :id => Unit.first assert_redirected_to unit_url(assigns(:unit)) end def test_destroy unit = Unit.first delete :destroy, :id => unit assert_redirected_to units_url assert !Unit.exists?(unit.id) end end ################################################ Aufruf des Test ################################################ ruby -Itest test/functional/units_controller_test.rb ################################################ Fehlermeldung ################################################ Loaded suite test/functional/units_controller_test Started FEFFFEFFF 1) Failure: test_create_invalid(UnitsControllerTest) [test/functional/units_controller_test.rb:34]: expecting <"new"> but rendering with <""> 2) Error: test_create_valid(UnitsControllerTest): ActionController::RoutingError: No route matches {:action=>"show", :controller=>"units"} test/functional/units_controller_test.rb:40:in `test_create_valid' 3) Failure: test_destroy(UnitsControllerTest) [test/functional/units_controller_test.rb:63]: Expected response to be a redirect to but was a redirect to . 4) Failure: test_edit(UnitsControllerTest) [test/functional/units_controller_test.rb:45]: expecting <"edit"> but rendering with <""> 5) Failure: test_index(UnitsControllerTest) [test/functional/units_controller_test.rb:17]: expecting <"index"> but rendering with <""> 6) Error: test_new(UnitsControllerTest): NoMethodError: undefined method `login_as' for test_new(UnitsControllerTest):UnitsControllerTest test/functional/units_controller_test.rb:26:in `test_new' 7) Failure: test_show(UnitsControllerTest) [test/functional/units_controller_test.rb:22]: expecting <"show"> but rendering with <""> 8) Failure: test_update_invalid(UnitsControllerTest) [test/functional/units_controller_test.rb:51]: expecting <"edit"> but rendering with <""> 9) Failure: test_update_valid(UnitsControllerTest) [test/functional/units_controller_test.rb:57]: Expected response to be a redirect to but was a redirect to . Finished in 1.50476625 seconds. 9 tests, 9 assertions, 7 failures, 2 errors, 0 pendings, 0 omissions, 0 notifications 0% passed 5.98 tests/s, 5.98 assertions/s