1) RfidT is not valid without device_mac
Failure/Error: expect(obj2.errors[:device_mac]).to include ("not valid without device_mac!")
expected [] to include "not valid without device_mac!"
# ./spec/models/rfid_t_spec.rb:20:in `block (2 levels) in <top (required)>'
2) RfidT duplicate values of epc are not allowed
Failure/Error: expect(obj3.errors[:epc]).to include("duplicate values of epc are not allowed!")
expected [] to include "duplicate values of epc are not allowed!"
# ./spec/models/rfid_t_spec.rb:27:in `block (2 levels) in <top (required)>'
3) RfidT is not valid without first_seen
Failure/Error: expect(obj4.errors[:first_seen]).to include("cannot be Blank!")
expected ["can't be blank"] to include "cannot be Blank!"
# ./spec/models/rfid_t_spec.rb:33:in `block (2 levels) in <top (required)>'
4) RfidT is not valid without last_seen
Failure/Error: expect(obj5.errors[:last_seen]).to include("cannot be Blank!")
expected ["can't be blank"] to include "cannot be Blank!"
# ./spec/models/rfid_t_spec.rb:39:in `block (2 levels) in <top (required)>'
Finished in 0.16685 seconds (files took 6.45 seconds to load)
6 examples, 4 failures
But when i am using to_not in place of to in spec file then i am not getting any error .Please tell me what is meaning of this and what is the diffrence between to and to_not in ruby and rails.
my spec file generating no error is:
require 'rails_helper'
RSpec.describe RfidT, type: :model do
it "is valid without epc,device_mac,first_seen,last_seen,count" do
obj=RfidT.new(epc:"abc",device_mac:"pqrs",first_seen:10,last_seen:20,count:200)
expect(obj).to be_valid
end
it "is not valid without epc" do
obj1=RfidT.new(epc:nil)
obj1.valid?
#expect(obj1.errors[:epc]).to include("cannot be Blank!")
expect(obj1).to_not be_valid
end
it"is not valid without device_mac " do
obj2=RfidT.new(device_mac:nil)
obj2.valid?
expect(obj2.errors[:device_mac]).to_not include ("not valid without device_mac!")
end
it" duplicate values of epc are not allowed" do
RfidT.create(epc:"abc",device_mac:"pqrs",first_seen:10,last_seen:20,count:200)
obj3=RfidT.new(epc:"abc",device_mac:"pqrs",first_seen:10,last_seen:20,count:200)
obj3.valid?
expect(obj3.errors[:epc]).to_not include("duplicate values of epc are not allowed!")
end
it "is not valid without first_seen " do
obj4=RfidT.new(first_seen:nil)
obj4.valid?
expect(obj4.errors[:first_seen]).not_to include("cannot be Blank!")
end
it "is not valid without last_seen " do
obj5=RfidT.new(last_seen:nil)
obj5.valid?
expect(obj5.errors[:last_seen]).to_not include("cannot be Blank!")
end
end
Aucun commentaire:
Enregistrer un commentaire