Topic: better test failure message

Hi all,

I'm writing my first rails application and I'm not sure how to make my test show with better error message.

My test is as below:

  test "should create task when post with value and minutes" do
    post :create, :task => { :value => "My great project", :minutes => 120 }
   
    assert_response :success
    assert_not_nil assigns(:task)
    assert_equal "Successfully created.", flash[:notice]
    assert_redirected_to task_path(assigns(:task)) # failed assert
  end


and test result show as:

1) Failure:
test_should_create_task_when_post_with_value_and_minutes(TasksControllerTest) [test/functional/tasks_controller_test.rb:11]:
Expected block to return true value.

2 tests, 5 assertions, 1 failures, 0 errors, 0 skips


I would like to have some meaningful error message for asserting.

Thanks.

Last edited by soemoe (2011-05-11 12:43:47)

Re: better test failure message

I am also looking for the right code in the application.

modern bedroom furniture | modern beds

Re: better test failure message

This might not be exactly what you're looking for but it helped me.
In integration tests it produces the full stack error, example when using for assert_response :success

if @response
    puts @response.template.instance_variable_get(:@exception).backtrace.join("\n")
end