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

Test Factories - errors

First, I must say, this video seems incredibly rushed to me. I know you're limiting yourself to time constraints, and I'm aware that you can pause the video - but I'm getting no sense of explanation of anything here. In addition, I don't know why you guys stopped adding complementary code where we could, as a last resort, compare to see any problems.

That said, I copied down the code for factories.rb from the screen anyway, word for word. Before that, I added factory_girl_rails to the gem file in the group :test do portion.. and bundle installed it. I've even run rake:test:prepare.

from the user_friendship_controller_test, I have

    should "create a user friendship" do
      assert users(:baggins).pending_friends.include?(users(:samwise))
    end

and in user_test I have

    test "that creating friendships on a user works" do
    users(:baggins).pending_friends << users(:samwise)
    users(:baggins).pending_friends.reload
    assert users(:baggins).pending_friends.include?(users(:samwise))
    end

Now for the errors

From the command prompt, I tested the user_friendships_controller_test and got this error:

 C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/factory_girl-4.2.0/lib/fact
 ory_girl/definition_proxy.rb:36:in `add_attribute': Both value and block given (
 FactoryGirl::AttributeDefinitionError)

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/factory_girl-4.2.0/lib/fact
ory_girl/definition_proxy.rb:36:in `add_attribute': Both value and block given (
FactoryGirl::AttributeDefinitionError)

Both said "Method missing". While the tests in the video ultimately went fine, I on the other hand got these errors.

4 Answers

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Thomas,

I'm really sorry about the lack of explanation :( What concepts did you feel needed more explanation? I'd be happy to answer any questions here.

Regarding your error, can you paste your test/factories.rb file here? I think that's where the problem is.

Hi Jason, yeah I realize you had to cover a lot of ground in a short period of time, and really it behooves us watching to read the documentation in addition. Otherwise, there's not enough time for you to go through all the details. Yeah I figured it was in the factories.rb file, but I couldn't figure out exactly what was missing.

    FactoryGirl.define do
       factory :user do
    first_name 'First'
    last_name 'Last'
    sequences(:email) {|n| "user#{n}@example.com"}
    sequence(:profile_name) {|n| "user#{n}"}

    password "mypassword"
    password_confirmation "mypassword"
end

    factory :user_friendship do
    association :user, factory: :user
    association :friend, factory: :user

    factory :pending_user_friendship do
        state 'pending'
    end

    factory :requested_user_friendship do
        state 'requested'
    end

    factory :accepted_user_friendship do
        state 'accepted'
    end
end
end
Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Try changing the line:

sequences(:email) {|n| "user#{n}@example.com"}

To:

sequence(:email) {|n| "user#{n}@example.com"}

Ah.. of course. I totally missed that. Bummer! Thank you.