Ruby 2.2.0 DataMapper: How to test numeric fields

时间:2018-05-06 17:13:21

标签: ruby validation ruby-datamapper

I am working on Ruby 2.2.0, I have a class

#world-map{
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
path:hover {
  stroke: #002868 !important;
  stroke-width:2px;
  stroke-linejoin: round;
  fill: #002868 !important;
  cursor: pointer;
}
.clicked {
  fill: #ff9800;
  stroke: #ff9800;
  stroke-width: 2px;
  stroke-linejoin: round;;
}

My question is: How I can test values of experience field in rspec tests? It's easy to test title, because I ask for valid? and it returns if title is present or not, but I don't know if is there something like this for numeric fields. Thanks in advance!

1 个答案:

答案 0 :(得分:0)

只是测试一个attr可以为给定的模型编写并不是很有用,因为它是ORM的核心功能的一部分,同样与验证器一样,但如果你真的想要,你可以测试创建一份新的工作机会,比如......

RSpec.describe JobOffer do
 describe ".new" do
   subject(:new) { JobOffer.new(experience: experience_in_years)}
   context "when intialized with experience of 5"
   let(:experience_in_years) { 5 }
   it "has an experience of 5" do
     expect(new.experience).to eq(5) 
   end
   end
 end
end

但同样,这几乎是ORM的核心功能,所以它可能不是一个有用的测试。