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

Errors in Scoping for Ruby on Rails website

I thought I was following the same code as the video, but I'm getting a weird set of errors:

ruby -Itest test/functional/profiles_controller_test.rb
test/functional/profiles_controller_test.rb:26: syntax error, unexpected $end, e
xpecting keyword_end

and here's the code, which I thought was identical to Jason's in the profile_controller_test

test "only shows the correct user's statuses" do
get :show, id: users(:baggins).profile_name
assigns(:statuses).each do |status|
  assert_equal users(:baggins), status.user
end
end

but when I add an extra end in there, I get 3 errors, namely they are like this:

  1) Error:
test_only_shows_the_correct_user's_statuses(ProfilesControllerTest):
NoMethodError: undefined method `Statuses' for #<User:0x4ec7ce0>

2 Answers

Ok, I fixed it. I knew I capitalized the wrong word, I just couldn't find which one. Alas, it was in the profile controller: @user.Statuses.all instead of @user.statuses.all. The weird triple end remains, but the code passes the test so I guess I shouldn't complain.

The wierd triple end remains

There should be three 'ends' on the final 3 lines of the test. Ensure you are properly nesting your code blocks, it makes the code much easier to debug and helps avoid syntax errors.

class ProfilesControllerTest < ActionController::TestCase
    # get show, render 404, variable assigned test cases

   test "only shows the current user's statuses" do
    get :show, id: users(:jason).profile_name
    assigns(:statuses).each do |status|
      assert_equal users(:jason), status.user
    end    #closes assigns(:statuses) .each do block
  end    # closes the "only shows the current user's statuses" test block    
end     #closes the ProfilesControllerTest class