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

Testing the statuses controller

I am having troubles getting my test to pass that makes sure a user should create a status when logged in.

I have changed my statuses_controller.rb code to:

class StatusesController < ApplicationController
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update]

Here is my test code:

test "should create status when logged in" do
    sign_in users(:jason)

    assert_difference('Status.count') do
    post :create, status: { content: @status.content }
   end

And here is the error message I get in terminal:

1) Failure: test_should_create_status_when_logged_in(StatusesControllerTest) [test/functional/statuses_controller_test.rb:34]: "Status.count" didn't change by 1. <3> expected but was <2>.

Any help is great!

1 Answer

The stuff in your status_controller.rb is fine. There is a slight difference. You have "ruby test" and it should just be test.

Did you also make sure that you put the second set of code in the status_controller_test.rb file?

Also, I'm not sure if you have the last 2 lines. If you do, then that's fine, but try my code in its place and see if it works. I hope it helps.

Your Code

   ruby test "should create status when logged in" 
   do sign_in users(:jason)

   assert_difference('Status.count') do
   post :create, status: { content: @status.content }
   end 

My Code

   test "should create status when logged in" do
    sign_in users(:jason)

    assert_difference('Status.count') do
      post :create, status: { content: @status.content }
    end
    assert_redirected_to status_path(assigns(:status))
   end