Something like that:
describe "#reject_body_scores" do
context "when record is new" do
let(:horse) { build :horse }
let(:options) { {} }
it "reject body" do
horse.send(:reject_body_scores, options).should be_true
end
end
context "when date blank" do
let(:horse) { create :horse }
let(:options) { {} }
it "reject body" do
horse.send(:reject_body_scores, options).should be_true
end
end
context "when score blank" do
let(:horse) { create :horse }
let(:options) { { "date" => Date.current } }
it "reject body" do
horse.send(:reject_body_scores, options).should be_true
end
end
context "when date and score present" do
let(:horse) { create :horse }
let(:options) { { "date" => Date.current, "score" => 5 } }
it "don't reject body" do
horse.send(:reject_body_scores, options).should be_false
end
end
end
You should cover all possible behaviors.
I've also used the trick using object.send
for testing private methods described here.
upd:
Since you new to testing I'll add some description about testing.
I've use FactoryGirl for creating new factories and use short syntax for that.
I've use let to assign new variables instead of before
block.