2012-07-26 26 views
0

我使用RSpec測試,我還在學習,我想我在正確的道路......但是當我測試我的RSpec的文件,我得到這個錯誤:故障/錯誤:預期{click_button提交}

Failures: 

1) UsersController signup with valid information should create a user 
Failure/Error: expect { click_button submit }.to change(User, :count).by(1) 
    count should have been changed by 1, but was changed by 0 
# ./spec/controllers/user_controller_spec.rb:31 

Finished in 1.16 seconds 

2例,1次失敗

知道這是什麼意思,但我不知道如何解決它,任何人都可以幫我這個麻煩,請...我也把我的RSpec的文件

require 'spec_helper' 

describe UsersController do 


describe "signup" do 

before { visit new_user_registration_path } 

let(:submit) { "Sign up" } 

describe "with invalid information" do 
    it "should not create a user" do 
    expect { click_button submit }.not_to change(User, :count) 
    end 
end 

describe "with valid information" do 
    before do 
    fill_in "Email", :with=> "[email protected]" 
    fill_in "Password", :with=> "foobar" 
    #fill_in "password_confirmation", :with=> "foobar" 
    end 

(這裏是錯誤出現在...下方)

 it "should create a user" do 
     expect { click_button submit }.to change(User, :count).by(1) 
     end 
    end 
    end 
end 

感謝您的關注

回答

0

所以,你有一個失敗的規範。規範本身看起來不錯。所以我會檢查

  • 是否執行到位?您可以在瀏覽器中試用該場景。它在那裏工作嗎?如果沒有,你有一個失敗的測試(這是很好的),並需要添加實現。
  • 如果實施有效,請再次仔細檢查規格。是所提供的信息

    FILL_IN 「電子郵件」,:用=> 「[email protected]」 FILL_IN 「密碼」:用=> 「foobar的」

    足以創建一個用戶?

  • 如果你還沒有找到原因,你可以使用capybaras save_and_open_page(爲此安裝launchy gem)並在測試過程中瀏覽頁面。

此外:

OK,就像我說的,這應該是一個集成測試 - 它從投機/移動控制器的規格/請求文件夾(不改變的第一線,爲你不描述UsersController!但不應該導致問題)。

+0

ps:如果您在調查時遇到問題,請發佈rspec中的實際故障(進一步在輸出中) - 另一件我注意到的事情:這是集成還是控制器測試? (它位於哪裏?) - 從文件我會說一個集成測試,但它說描述UsersController。請參閱http://stackoverflow.com/questions/5932605/capybara-rspec-only-sees-blank-pages-in-controller-specs-爲了討論。 – bento 2012-07-26 14:31:32

+0

感謝您的回答,閱讀您的文章,我猜測規範不夠充分,因爲實施工作 – Asantoya17 2012-07-26 14:44:33

+0

可以發佈失敗規範的完整輸出嗎? – bento 2012-07-26 14:50:03