multiple testing in one book

34 views
Skip to first unread message

Roelof Wobben

unread,
Nov 29, 2014, 7:58:15 AM11/29/14
to minites...@googlegroups.com
Hello,

Im now following Hartl tutorial and I see that he test multiple things in one test.

See this example :

 test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Home | #{@base_title}"
  end

I thought  it was Always better to test one thing a test.

What is your oponion about this ?

Roelof

Mike Moore

unread,
Nov 29, 2014, 12:39:26 PM11/29/14
to minites...@googlegroups.com
The following is just my opinion... Like most things in Rails the "best practices" are sacrificed on the alter of convenience.

Normally I agree that each test should test just one thing. Testing one thing is not the same as one assertion, despite what some may say. Those two assertions are there to make sure that "should get home" does in fact do the right thing. So I don't see that as a violation test just one thing rule.

That said, tests in Rails are expensive. Each test is wrapped in a database transaction. Each controller test creates a controller instance, calls the controller, invokes the router, and parses and renders templates. That adds up. So I am more lenient on rails tests testing more than one thing because the setup is so expensive, but those cases are still rare. 
Reply all
Reply to author
Forward
0 new messages