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

Friendship Controller ArgumentError

Hey guys at the very end of the "building a friendship controller" tutorial I got an error not like the one shown in the video.

1) Error:

test: #new when logged in should display friends name. (UserFriendshipsControllerTest):
ArgumentError: wrong number of arguments (1 for 0)
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack3.2.6/lib/action_controller/metal.rb:143:in `params'

There are 2 other errors but they are identical to this one, here is the tests I had up till that point:

require 'test_helper'

class UserFriendshipsControllerTest < ActionController::TestCase
    context "#new"  do
        context "when not logged in" do
            should "redirect to the login page" do
                get :new
                assert_response :redirect
            end
    end
    context "when logged in" do
        setup do
            sign_in users(:allan)
        end
        should "get new and return success" do
            get :new
            assert_response :success
        end
        should "should set a flash error if the friend_id params is missing" do
            get :new, {}
            assert_equal "Friend required", flash[:error]
        end
        should "display friends name" do
            get :new, friend_id: users(:drew).id
            assert_match /#{users(:drew).full_name}/, response.body
        end
    end 
    end
end

I'll keep digging, let me know if you see anything missing.

[ed. note]: Added markdown to fix code formatting

4 Answers

Sorry the code looks cramped, it didn't keep the spaces when I posted the message, also I got a similar error when working on the code challenge, would the error be caused by having to many "end"s in my test file?

What's with the get :new, {} assert_equal? Are the brackets supposed to be there? I think that could be your error. Seems like your trying to call some function and that's giving you the argument error?

I'm running the same test but getting different results, says a syntax error now:

C:\Sites\Projects\treebook>ruby -I test test/functional/user_friendships_control ler_test.rb test/functional/user_friendships_controller_test.rb:24: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' get :new, assert_equal "Friend required", flash[:error]