2017-12-18 1 views
2

レールだから、これはレポ https://github.com/Mroczeks/first_project であり、これは誤りであります:user_test.rbファイルにあなたの@userオブジェクトを保存する際はID HARTLせずにユーザーが見つかりませんでした私はrailstutorial.orgから勉強 レールに自分のプロジェクトに問題があると私は〜6.18 をリストで問題を抱えているチュートリアル

rails test 
Running via Spring preloader in process 10776 
Started with run options --seed 33787 

FAIL["test_schould_be_valid", UserTest, 0.6801217989996076] 
test_schould_be_valid#UserTest (0.68s) 
     Expected false to be truthy. 
     test/models/user_test.rb:9:in `block in <class:UserTest>' 

ERROR["test_email_addresses_should_be_saved_as_lower-case", UserTest, 0.6879979369996363] 
test_email_addresses_should_be_saved_as_lower-case#UserTest (0.69s) 
ActiveRecord::RecordNotFound:   ActiveRecord::RecordNotFound: Couldn't find User without an ID 
      test/models/user_test.rb:45:in `block in <class:UserTest>' 

FAIL["test_email_validation_should_accept_valid_addresses", UserTest, 0.7056386839994957] 
test_email_validation_should_accept_valid_addresses#UserTest (0.71s) 
     "[email protected]" should be valid 
     test/models/user_test.rb:32:in `block (2 levels) in <class:UserTest>' 
     test/models/user_test.rb:30:in `each' 
     test/models/user_test.rb:30:in `block in <class:UserTest>' 

    18/18: [=================================] 100% Time: 00:00:00, Time: 00:00:00 

Finished in 0.78367s 
18 tests, 29 assertions, 2 failures, 1 errors, 0 skips 
+0

'test/models/user_test.rb'ファイルには何がありますか? –

+0

モデルユーザー(名前、電子メール、bcryptのパス)をテストします。たとえば、パスワードが空であるか、指定された文字数があるかをテストします。 – Drekoo

+0

https://github.com/Mroczeks/first_project/blob/master/test/models/user_test.rb – Drekoo

答えて

3

このエラーの原因は、検証を失敗しているように見えます。以下のコードでこのテストを交換してみて、このテストを実行するとき、あなたは失敗の検証が表示されます。

test "email addresses should be saved as lower-case" do 
    mixed_case_email = "[email protected]" 
    @user.email = mixed_case_email 

    # Calling `save!` here will raise an exception if failed to save @user. 
    @user.save! 
    assert_equal mixed_case_email.downcase, @user.reload.email 
end 

はそれに応じてすべての検証を満たし、もう一度試してくださいsetup方法を修正します。 Userモデルで

3

、あなたは最低でも6であることをdefined password length validationを持っていますが、テストのセットアップ、password: 'pies'created the userインチしたがって、あなたはすべてのエラーや障害になっている:すべてのエラーを解決するには

FAIL["test_schould_be_valid", UserTest, 0.6801217989996076] 
test_schould_be_valid#UserTest (0.68s) 
    Expected false to be truthy. 
    test/models/user_test.rb:9:in `block in <class:UserTest>' 

を、あなたはUserTest#setupで有効なデータを持つユーザーを初期化する必要があります。この場合、最小長さ6のパスワードを入力する必要があります。

関連する問題