I have been toying with rspec for a couple of days in a new project, but 
I'm running into something that looks a bit weird, and I'm not sure if I am 
doing it right. I'm using padrino with mongoid. I have been using 
shoulda-like matchers (mongoid-rspec), but it seems I am duplicating a lot 
of code, and I'm not sure I am really adding any value.... I'm writing a 
lot of 

it { should validate_presence_of(:name) }
it { should validate_uniqueness_of(:clinical_record) }
ecc.....

For example, I have an Appointment model, that have the saturation of the 
Patient, the saturation must be an integer and between 1 and 100. In the 
model, I can write:

# models/appointment.rb
validates :saturation, numericality { only_integer: true, greater_than: 0, 
less_than_or_equal_to: 100 }

field :saturation, type: Integer

# spec/models/appointment_spec.rb
it { should 
validate_numericality_of(:saturation).greater_than(0).less_than_or_equal_to(100)
 
}

This obviously pass, but I realized this wasn't testing a real use, so 
since some models were particularly long, I thought using a factory would 
help:

# spec/models/appointment_spec.rb
# I also tried to start using boundary testing since I was going to start 
testing ranges
it "should not allow saturation over 100" do
  appointment = build(:appointment, saturation: 101)
  expect(Appointment.create(saturation: appointment.saturation)).to_not 
be_valid
end

^ pass

But it looks kind of ugly, and since I have to make a couple more examples 
(not allowing 0 [or less], allowing edge cases [1 and 100], ecc) am I doing 
this right? I have some small models, but very long specs :/

Regards =)




-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/984d31a7-d49a-47da-85b4-bc5497ce0f26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to