2017-12-18 7 views
2

내가 railstutorial.org에서 배우고 레일 을 내 프로젝트에 문제가 레일 그리고 난 ~ 목록에서 문제가 6.18 그래서이 REPO https://github.com/Mroczeks/first_project 입니다 그리고 이것은 오류입니다 :는 튜토리얼

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]le.com" 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

이 오류의 원인은 user_test.rb 파일에 @user 객체를 저장할 때 검증을 실패 할 것으로 보인다. 아래의 코드로이 테스트를 교체 시도하고이 테스트를 실행할 때 당신은 실패한 검증이 표시됩니다

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 인 비밀번호를 제공하면됩니다.