Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Build a Simple Ruby on Rails Application

Testing Responses: Challenge 1 of 1

Add an assertion to make sure the response was successful

At first I thought it was:

assert_response :successful

(seems logical, right?)

after much searching on the forum I came across this post:

https://teamtreehouse.com/forum/ror-creating-the-friendship-error

that had this code:

    should "get new and return success" do
        get :new
        assert_response :success
    end

Hmmmmmm - so I thought maybe:

        get :new

        assert_response :success

but nooooooooooooooo!

Alright, then...maybe just drop the

get :new (don't repeat it twice..because it already has one 'get:new' to start with..

Yes! It passed (whew)

Morale of the story: don't over think this question, but do search the forum for code snippets --there is a lot of good content there :)

Oh, here's the link to the challenge:

http://teamtreehouse.com/library/build-a-simple-ruby-on-rails-application/testing-the-whole-app/testing-responses

1 Answer

Stone Preston
Stone Preston
42,016 Points

can you post a link to the challenge? i cant give you a definite answer without seeing it myself but the Rails Testing Guide lists some of the assertions that come with mini test, one of them being

assert_response

Asserts that the response comes with a specific status code. You can specify :success to indicate 200-299, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range. You can also pass an explicit status number or its symbolic equivalent.

so to assert that the response was successful you would use:

assert_response :success