ユーザ(staff)モデルのテスト作成のエラー
学び:どうしてエラーなのかが全然わからない....byebugを使う
Failures:
1) Staff バリテーション name,email値が設定されていれば、OK
Failure/Error: expect(@staff.valid?).to eq(true)
expected: true
got: false
(compared using ==)
Diff:
@@ -1 +1 @@
-true
+false
# ./spec/models/staff_spec.rb:15:in `block (3 levels) in <top (required)>'
Finished in 0.38805 seconds (files took 2.01 seconds to load)
4 examples, 1 failure, 1 pending
Failed examples:
rspec ./spec/models/staff_spec.rb:14 # Staff バリテーション name,email値が設定されていれば、OK
該当箇所
```ruby: describe 'バリテーション' do it 'name,email値が設定されていれば、OK' do expect(@staff.valid?).to eq(true) end : ```該当箇所にbyebug入れる
```ruby: describe 'バリテーション' do it 'name,email値が設定されていれば、OK' do byebug ######ここ expect(@staff.valid?).to eq(true) end : ```動かす
``` $ bundle exec rspec ./spec/models/staff_spec.rb ``` ```ruby: (main) $ bundle exec rspec ./spec/models/staff_spec.rb #打ったところ 2021-09-18 13:27:29 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.Staff
add some examples to (or delete) /home/ec2-user/environment/stoma/spec/models/staff_spec.rb (PENDING: Not yet implemented)
バリテーション
[11, 20] in /home/ec2-user/environment/stoma/spec/models/staff_spec.rb
11: end
12:
13: describe 'バリテーション' do
14: it 'name,email値が設定されていれば、OK' do
15: byebug
=> 16: expect(@staff.valid?).to eq(true)
17: end
18:
19: it 'nameが空はNG' do
20: @staff.name = ''
(byebug) #次にここに入れる
<h2>(byebug)に入力する</h2>
```ruby:
:
(byebug)@staff.valid!
*** NoMethodError Exception: undefined method `valid!' for #<Staff:0x0000000007ac6f28>
Did you mean? valid?
nil
(byebug) @staff
# <Staff id: nil, email: "test1@example.com", name: "TEST_NAME1", created_at: nil, updated_at: nil>
saveできているか確認する @staff.save!
```ruby: (byebug) @staff.save! *** ActiveRecord::RecordInvalid Exception: バリデーションに失敗 しました: Passwordを入力してくださいnil
(byebug) continue
name,email値が設定されていれば、OK (FAILED - 1)
nameが空はNG
emailが空はNG
Pending: (Failures listed here are expected and do not affect your suite's status)
<h2>passwordがバリテーションのデータ設定されていないことがわかる</h2>
```ruby:
nvironment/stoma (main) $ bundle exec rspec ./spec/models/staff_spec.rb
2021-09-18 13:27:29 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chrome::Service#driver_path= instead.
Staff
add some examples to (or delete) /home/ec2-user/environment/stoma/spec/models/staff_spec.rb (PENDING: Not yet implemented)
バリテーション
[11, 20] in /home/ec2-user/environment/stoma/spec/models/staff_spec.rb
11: end
12:
13: describe 'バリテーション' do
14: it 'name,email値が設定されていれば、OK' do
15: byebug
=> 16: expect(@staff.valid?).to eq(true)
17: end
18:
19: it 'nameが空はNG' do
20: @staff.name = ''
(byebug) @staff.valid?
false
(byebug) @staff.valid!
*** NoMethodError Exception: undefined method `valid!' for #<Staff:0x0000000007ac6f28>
Did you mean? valid?
nil
(byebug) @staff
# <Staff id: nil, email: "test1@example.com", name: "TEST_NAME1", created_at: nil, updated_at: nil>
(byebug) @staff.save!
*** ActiveRecord::RecordInvalid Exception: バリデーションに失敗 しました: Passwordを入力してください
nil
(byebug) continue
name,email値が設定されていれば、OK (FAILED - 1)
nameが空はNG
emailが空はNG
Pending: (Failures listed here are expected and do not affect your suite's status)
1) Staff add some examples to (or delete) /home/ec2-user/environment/stoma/spec/models/staff_spec.rb
# Not yet implemented
# ./spec/models/staff_spec.rb:4
Failures:
1) Staff バリテーション name,email値が設定されていれば、OK
Failure/Error: expect(@staff.valid?).to eq(true)
expected: true
got: false
(compared using ==)
Diff:
@@ -1 +1 @@
-true
+false
# ./spec/models/staff_spec.rb:16:in `block (3 levels) in <top (required)>'
Finished in 3 minutes 39.8 seconds (files took 1.99 seconds to load)
4 examples, 1 failure, 1 pending
Failed examples:
rspec ./spec/models/staff_spec.rb:14 # Staff バリテーション name,email値が設定されていれば、OK