3

I'm running rails 3.0.9 and ruby 1.9.2 and working from the Hartl ruby on rails tutorial. I'm also running spork. Using factory_girl_rails v. 1.1.0

Failures:

  1) UsersController GET 'show' should be successful
     Failure/Error: @user = Factory(:user)
     ActiveRecord::RecordInvalid:
       Validation failed: Name can't be blank
     # ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

Finished in 0.38122 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/controllers/users_controller_spec.rb:12 # UsersController GET 'show' should be successful

Mr factories.rb file

Factory.define :user do |user|

  user.name "Michael Hartl"
  user.email "mhartl@example.com"
  user.password "foobar"
  user.password_confirmation "foobar"

end

User_controller_spec.rb file

require 'spec_helper'

describe UsersController do
  render_views

  describe "GET 'show'" do

    before(:each) do
      @user = Factory(:user)
    end

    it "should be successful" do 
      get :show, :id => @user 
      response.should be_success
    end

    # it "show the right user" do
    #      get :show, :id  => @user
    #      assigns(:user).should == @user
    #    end
  end

  describe "GET 'new'" do
    it "should be successful" do
      get 'new'
      response.should be_success
    end

  it "should have the right title" do
    get :new
    response.should have_selector('title', :content => "Sign up")
    end
  end

end

show.html.rb file

<%= @user.name %>, <%= @user.email %>
javascriptttt
  • 730
  • 5
  • 15
  • Added factory_girl_rails 1.0 back (I had previously tried 1.1.0 as 1.0 wouldn't work) without removing 1.1.0 and it's now working. Not sure I understand why but... – javascriptttt Aug 11 '11 at 07:29

1 Answers1

1

Just a thought, but did you restart the Spork server? This is sometimes necessary, see Spork: how to refresh validations and other code? for more info.

Community
  • 1
  • 1
matthew.tuck
  • 1,267
  • 9
  • 11