Unit test code for a model using RSpec, which has a little peculiarity ~ User registration

Introduction

It's completely for me. I will leave the quirky code for unit testing (user registration) of the model.

mail address

user_spec.rb


it 'mail address is,@Must include' do
  @user.email.delete!('@')
  @user.valid?
  expect(@user.errors.full_messages).to include("Email address is incorrect")
end

password

user_spec.rb


it 'The password must be entered with at least 6 characters' do
  @user.password = '12345'
  @user.password_confirmation = @user.password
  @user.valid?
  expect(@user.errors.full_messages).to include("Please enter the password with at least 6 characters")
end

user_spec.rb


it 'The password must be entered without half-width alphabetic characters.' do
  @user.password = '123456'
  @user.password_confirmation = @user.password
  @user.valid?
  expect(@user.errors.full_messages).to include("Password is an invalid value")
end

user_spec.rb


it 'The password must be entered without half-width numbers.' do
  @user.password = 'abcdef'
  @user.password_confirmation = @user.password
  @user.valid?
  expect(@user.errors.full_messages).to include("Password is an invalid value")
end

user_spec.rb


it 'Password cannot be registered with double-byte numbers' do
  @user.password = '12345a'
  @user.password_confirmation = @user.password
  @user.valid?
  expect(@user.errors.full_messages).to include("Password is an invalid value")
end

user_spec.rb


it 'Password and password (Kakunin), value matching is required' do
  @user.password = '12345a'
  @user.password_confirmation = '12345b'
  @user.valid?
  expect(@user.errors.full_messages).to include("The password (Kakunin) and password input do not match")
end

Recommended Posts

Unit test code for a model using RSpec, which has a little peculiarity ~ User registration
[Rails] Unit test code for User model
[Rspec] Flow from introducing Rspec to writing unit test code for a model
[For beginners] Test devise user registration with RSpec
After introducing RSpec, until you start writing unit test code for your model
RSpec unit test code creation procedure (login user creation Ver.)
[Rails] Test code using Rspec
About method matchers used in model unit test code (RSpec)
[RSpec] Unit test (using gem: factory_bot)
Introduce RSpec and write unit test code
Why you need a bundle exec
[For beginners] Test devise user registration with RSpec
Model unit test code to check uniqueness constraints
[RSpec] I wrote a test for uploading a profile image.
[Rails] From test preparation to model unit testing [RSpec]
How to write a unit test for Spring Boot 2
[Rails / RSpec] Write Model test (using Shoulda Matchers / FactoryBot)