2011-07-22 55 views
4

我需要Rspec後衛連續運行我的測試,但有時測試失敗的原因爲:未初始化的常量的RSpec ::核心:: ExampleGroup :: Nested_1 ::廠

Running: spec/requests/signup_spec.rb 
FF 

Failures: 

    1) Signup does not email confirmation mail after signup 
    Failure/Error: visit new_user_path 
    NameError: 
     undefined local variable or method `new_user_path' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000100ad5fd8> 
    # ./spec/requests/signup_spec.rb:4:in `block (2 levels) in <top (required)>' 

    2) Signup should email confirmation mail after signup 
    Failure/Error: user = Factory.build(:user) 
    NameError: 
     uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Factory 
    # ./spec/requests/signup_spec.rb:15:in `block (2 levels) in <top (required)>' 

有時他們的工作,有時他們不工作..我不知道爲什麼..

你能幫我嗎?

編輯: 我使用以下版本:

  • 紅寶石1.9.2-P290
  • 軌3.1.rc4
  • rspec的(2.6.0)
  • RSpec的護欄(2.6 .1)
  • factory_girl(2.0.0.rc4)
  • factory_girl_rails(1.1.rc1)

正如你所看到的,這些路線並不工作:new_user_path找不到...?

這是我的要求規格:

# -*- encoding : utf-8 -*- 
describe "Signup" do 
    it "does not email confirmation mail after signup" do 
    visit new_user_path 
    fill_in 'user_unconfirmed_email', :with => '[email protected]' 
    fill_in 'user_password', :with => '' 
    fill_in 'user_password_confirmation', :with => '' 
    click_button "Create User" 
    current_path.should eq(user_path) 
    page.should have_content("is too short") 
    last_email.should be_nil 
    end 

    it "should email confirmation mail after signup" do 
    user = Factory.build(:user) 
    visit root_path 
    fill_in 'user_unconfirmed_email', :with => user.unconfirmed_email 
    fill_in 'user_password', :with => user.unconfirmed_email 
    fill_in 'user_password_confirmation', :with => user.unconfirmed_email 
    click_button "Create User" 
    current_path.should eq(root_path) 
    page.should have_content("You successfully signed up! An email with your activation link was sent to your mail address.") 
    last_email.to.should include(user.unconfirmed_email) 
    last_email.body.should include(user.email_confirmation_key) 
    open_email(user.unconfirmed_email) 
    click_first_link_in_email # email spec 
    current_path.should eq(new_user_path) 
    page.should have_content "Your email was successfully confirmed. You are now able to log in with it!" 
    end 
end 

回答

19

啊...找到了解決辦法。我忘了,包括

require 'spec_helper.rb' 
在我的規格

...

+0

感謝發佈這個,也發生在我身上。 – jcollum

2

我這個完全相同的問題,但在我的情況下,我忘了重啓spork。

Spork是一款使用rspec大大縮短測試持續時間的寶石。推薦的!

+0

spork讓我也... ...謝謝你的提示。 – PeppyHeppy

1

我有同樣的問題,但在我的情況下,我錯誤地根據規格/型號有我的規格,而它應該已在規格/要求下。

相關問題