Forum: Ruby on Rails Trouble with rspec and FactoryGirl Sequence

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
266f821f43d49b5e6b513d79e072abfe?d=identicon&s=25 Ray G. (ray_g)
on 2013-10-08 03:26
I'm following Michael Hartl's Ruby on Rails 3 Tutorial but I'm using
Rails 3.2.8 and FactoryGirl 4.2.0 and rspec 2.14.1   I'm in chapter 10
trying to generate tests for pagination (using will_paginate 3.2.5 which
works fine in dev)

I can get FactoryGirl to test just fine if I don't use Sequence but I
can't seem to figure out the correct syntax to test pagination using
sequence.  Very new to Ruby.

Here's what my factories.rb looks like:
FactoryGirl.define do
  factory :user do
    name "John Smith"
    sequence :email do |n|
      "person-#{n}@factory.com"
    end
    password "foobar"
    password_confirmation "foobar"
  end
end

Here's the relevant section of my users_controller_spec.rb:
require 'spec_helper'
  describe UsersController do
    .
    .
    describe "GET 'index'" do
      .
      .
      describe "for signed-in users" do
        before(:each) do
          @user = test_sign_in(FactoryGirl.create(:user))
          second = FactoryGirl.create(:user,
                   :email => "another@example.com")
          third = FactoryGirl.create(:user,
                   :email => "another@example.net")
          @users = [@user, second, third]
          30.times do
          @users << FactoryGirl.create(:user,
                    :email => FactoryGirl.generate(:email))
        end
      end

      it "should have the right title" do
        get :index
        response.should have_selector("title", :content => "All users")
      end
      .
      .

All my "get :index" tests are failing in the "for signed-in users" block
fail.  They don't fail if I just manually create a list of 30 users so
something is wrong with how I am trying to sequence or generate.

Thanks for helping this newb..
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2013-10-08 09:05
(Received via mailing list)
On 8 October 2013 02:26, Ray G. <lists@ruby-forum.com> wrote:
> I'm following Michael Hartl's Ruby on Rails 3 Tutorial but I'm using
> Rails 3.2.8 and FactoryGirl 4.2.0 and rspec 2.14.1

Don't do this, for a tutorial always use exactly the version of
everything that the tutorial expects, otherwise you never know why
things are not working correctly.  You never know whether it is
because you have mis-typed something from the tutorial or just a
difference because of the different versions.  Why can you not use the
expected versions?

Colin
This topic is locked and can not be replied to.