Reputation: 1
I am trying to test my admin model with rspec but I am facing error how to solve this error please give me some idea.
my model/admin_spec.rb is
require 'spec_helper'
describe Admin do
before do
@admin = Admin.new(email: "[email protected]", hash: "iJXdppRiI52XsqJe", password: "736fc7f1f4f382e79f2278817d056a0ec14b9ff5", city_id: "", role_id: 4, request_hash: "", status: 1)
end
subject { @admin }
it { should respond_to :email }
it { should respond_to :password }
it { should respond_to :phone }
it { should be_valid }
end
And the error is:
) Admin phone with valid format
Failure/Error: it { should be_valid }
expected valid? to return true, got false
# ./spec/models/admin_spec.rb:15:in `block (3 levels) in <top (required)>'
Finished in 16.08 seconds
34 examples, 1 failure
Failed examples:
rspec ./spec/models/admin_spec.rb:15 # Admin phone with valid format
Randomized with seed 31486
Upvotes: 0
Views: 215
Reputation: 15788
It looks like you have a validation on the phone attribute of Admin but you never set it in your test subject. Try setting it inside the before block with a valid phone attribute and the test should pass.
before do
@admin = Admin.new(phone: "01234568", email: "[email protected]", hash: "iJXdppRiI52XsqJe", password: "736fc7f1f4f382e79f2278817d056a0ec14b9ff5", city_id: "", role_id: 4, request_hash: "", status: 1)
end
Upvotes: 2