2014-10-01 92 views
1

我試圖運行示例應用程序的耙測試,我有1個錯誤,我似乎無法移位。運行耙測試問題第7章

`ERROR["test_invalid_signup_information", UsersSignupTest, 0.717775303]  test_invalid_signup_information#UsersSignupTest (0.72s)ArgumentError:   ArgumentError: unknown  command 'v'   test/integration/users_signup_test.rb:15:in `test'    test/integration/users_signup_test.rb:15:in `block in <class:UsersSignupTest>'   test/integration/users_signup_test.rb:15:in `test'  test/integration/users_signup_test.rb:15:in  `block in <class:UsersSignupTest>' 
    16/16: [=] 100% Time: 00:00:00, Time: 00:00:00 

Finished in 0.72207s 
16 tests, 34 assertions, 0 failures, 1 errors, 0 skips1 

它似乎指向我已粘貼在下面的users_signup頁面。

`require 'test_helper' 

class UsersSignupTest < ActionDispatch::IntegrationTest 

    test "invalid signup information" do 
    get signup_path 
    assert_no_difference 'User.count' do 
     post users_path, user: { name: "", 
           email: "[email protected]", 
           password:    "foo", 
           password_confirmation: "bar" } 
    end 
    assert_template 'users/new' 

    test "valid signup information" do 
    get signup_path 
    name  = "Example User" 
    email = "[email protected]" 
    password = "password" 
    assert_difference 'User.count', 1 do 
     post_via_redirect users_path, user: { name: name, 
              email: email, 
              password:    password, 
              password_confirmation: password } 
    end 
    assert_template 'users/show' 
    end 
    end 
end 

任何人都可以看到錯誤嗎?

+0

有看在第一次測試缺少'end',也有一個假'「'」'旁要求(第一行)? – AnkitG 2014-10-01 15:05:11

+0

已添加額外的'結束'標記,現在測試失敗,因爲結尾標記太多。 – 2014-10-02 09:18:08

+0

我有類似的問題,但這是因爲我已經做了'post'而不是'post_via_redirect' – 2014-12-15 23:54:27

回答

0

也許是因爲你沒有關閉第一次測試的控制流結構?有一個end失蹤。

嘗試用這樣的代碼:

require 'test_helper' 

class UsersSignupTest < ActionDispatch::IntegrationTest 

    test "invalid signup information" do 
    get signup_path 
    assert_no_difference 'User.count' do 
     post users_path, user: { name: "", 
           email: "[email protected]", 
           password:    "foo", 
           password_confirmation: "bar" } 
    end 
    assert_template 'users/new' 
    end 

    test "valid signup information" do 
    get signup_path 
    name  = "Example User" 
    email = "[email protected]" 
    password = "password" 
    assert_difference 'User.count', 1 do 
     post_via_redirect users_path, user: { name: name, 
              email: email, 
              password:    password, 
              password_confirmation: password } 
    end 
    assert_template 'users/show' 
    end 
end 
+0

已經添加了額外的'end'標籤,現在測試失敗,因爲已經有太多結束標籤 – 2014-10-02 10:33:32

+0

。謝謝你的幫助 – 2014-10-03 14:04:38