Below is an example of a RSpec 2 – Model test in a item_spec.rb file:
context “maximum score” do
it “should return maximum score of 0 when there is no item ratings” do
section=Section.create(:section_config=>@section_config, :review => @review)
item=Item.create(:section=>section)
item.maximum_score.should==0
end
it “should return the maximum score when there is an item rating” do
ItemRating.create(title: ‘High’, value: 4, :section_config => @section_config)
ItemRating.create(title: ‘High’, value: 8, :section_config => @section_config)
section=Section.create(:section_config=>@section_config, :review => @review)
item=Item.create(:section=>section)
item.maximum_score.should==8
end
end
Leave a Reply