2013-01-18 36 views
0

的運行當我運行rspec的投機/請求/ users_spec.rbrspec的不是因爲factorygirl

我得到這個:

[email protected]:~/Desktop/sample_app$ rspec spec/requests/users_spec.rb 
No DRb server is running. Running in local process instead ... 
Rack::File headers parameter replaces cache_control after Rack 1.5. 
/Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:6:in `define': wrong number of arguments (1 for 0) (ArgumentError) 
    from /Users/admin/Desktop/sample_app/spec/factories.rb:4:in `<top (required)>' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:16:in `block in find_definitions' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:15:in `each' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:15:in `find_definitions' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/factory_girl_rails-4.1.0/lib/factory_girl_rails/railtie.rb:26:in `block in <class:Railtie>' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in `call' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:42:in `each' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application/finisher.rb:59:in `block in <module:Finisher>' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing' 
    from /Users/admin/Desktop/sample_app/config/environment.rb:5:in `<top (required)>' 
    from /Users/admin/Desktop/sample_app/spec/spec_helper.rb:8:in `require' 
    from /Users/admin/Desktop/sample_app/spec/spec_helper.rb:8:in `block in <top (required)>' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/spork-0.9.2/lib/spork.rb:24:in `prefork' 
    from /Users/admin/Desktop/sample_app/spec/spec_helper.rb:3:in `<top (required)>' 
    from /Users/admin/Desktop/sample_app/spec/requests/users_spec.rb:1:in `require' 
    from /Users/admin/Desktop/sample_app/spec/requests/users_spec.rb:1:in `<top (required)>' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `block in load_spec_files' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `each' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:789:in `load_spec_files' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:22:in `run' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:77:in `rescue in run' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:73:in `run' 
    from /Users/admin/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun' 

這是factories.rb:

# By using the symbol ':user', we get Factory Girl to simulate the User model. 
# we can create a User factory in the tests like this: 
# @user = Factory(:user) 
FactoryGirl.define :user do |user| 
    user.name "Pavan Katepalli" 
    user.email "[email protected]" 
    user.password "foobar" 
    user.password_confirmation "foobar" 
end 

這是users_spec:

require 'spec_helper' 
require 'factory_girl_rails' 

describe "Users" do 

    describe "signup" do 

     describe "failure" do 
      it "should not make a new user" do 
       lambda do 
        visit signup_path 
        fill_in "Name",   :with => "" 
        fill_in "Email",  :with => "" 
        fill_in "Password",  :with => "" 
        fill_in "Confirmation", :with => "" 
        click_button 
        response.should render_template('users/new') 
        response.should have_selector('div#error_explanation') 
       end.should_not change(User, :count) 
      end 
     end 

     describe "success" do 
     it "should make a new user" do 
     lambda do 
      visit signup_path 
      fill_in "Name",   :with => "Example User" 
      fill_in "Email",  :with => "[email protected]" 
      fill_in "Password",  :with => "foobar" 
      fill_in "Confirmation", :with => "foobar" 
      click_button 
      response.should have_selector('div.flash.success', 
             :content => "Welcome") 
      response.should render_template('users/show') 
     end.should change(User, :count).by(1) 
     end 
    end 


    end 

end 

th是是users_controller_spec.rb:

require 'spec_helper' 
require 'factory_girl_rails' 

describe UsersController do 

    render_views 

    describe "GET 'show'" do 

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

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

     it "should find the right user" do 
      get :show, :id => @user.id 

      # assigns(:user) returns the 
      # value of the instance variable @user 
      assigns(:user).should == @user 
     end 

     it "should have the right title" do 
      get :show, :id => @user.id 
      response.should have_selector('title', :content => @user.name) 
     end 

     it "should have the user's name" do 
      get :show, :id => @user.id 
      response.should have_selector('h1', :content => @user.name) 
     end 

     it "should have a profile image" do 
      get :show, :id => @user.id 
      response.should have_selector('h1>img', :class => "gravatar") 
     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 

    describe "POST 'create'" do 

     describe "failure" do 

      before(:each) do 
       @attr = { :name => "", :email => "", :password => "", 
         :password_confirmation => "" } 
      end 

      it "should not create a user" do 
       lambda do 
        post :create, :user => @attr 
       end.should_not change(User, :count) 
      end 

      it "should have the right title" do 
       post :create, :user => @attr 
       response.should have_selector('title', :content => "Sign up") 
      end 

      it "should render the 'new' page" do 
       post :create, :user => @attr 
       response.should render_template('new') 
      end 
     end 

     describe "success" do 

      before(:each) do 
       @attr = { :name => "New User", :email => "[email protected]", 
         :password => "foobar", :password_confirmation => "foobar" } 
      end 

      it "should create a user" do 
       lambda do 
        post :create, :user => @attr 
       end.should change(User, :count).by(1) 
      end 

      it "should redirect to the user show page" do 
       post :create, :user => @attr 
       response.should redirect_to(user_path(assigns(:user))) 
      end 

      it "should have a welcome message" do 
       post :create, :user => @attr 
       flash[:success].should =~ /welcome to the sample app/i 
      end 

     end 
    end 



end 
+0

它是否幫助,如果你使用'factory'而不是' FactoryGirl.define'? –

+0

我會嘗試,但他們更新了寶石,使它FactoryGirl代替。愚蠢的更新。 –

+0

只是試了一下,得到了同樣的結果。這是我的github:https://github.com/railstutorial/sample_app/ –

回答

1

您鏈接回購是很老的(最後一次提交的規範文件夾是2年前),你可能已經得到了寶石(包括FactoryGirl)的較新版本的使用已安裝。

現在你可以做什麼是你的前綴電話rspecbundle exec,這將在的RSpec在當前的包中的寶石的上下文中運行:

bundle exec rspec spec/requests/users_spec.rb 
+0

嘿謝謝:)。但我正在使用Factory Girl的最新版本。我將用你給我的工廠女孩​​文件的鏈接修改它。 –

+0

嘿,我剛剛切換到1.7版的寶石和代碼工作。感謝您的幫助:)。 –

+0

沒問題,很高興我能幫忙! :) –

相關問題