Last active
January 24, 2016 17:25
-
-
Save aldesantis/bded51a0e0449d94f769 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe MyModel do | |
subject { MyModel.new } | |
%w(attribute1 attribute2 attribute3).each do |attribute| | |
it "adds an error when #{attribute} is not divisible by 0.5" do | |
subject.send("#{attribute}=", 1.3) | |
subject.validate | |
expect(subject.errors.messages[attribute]).to eq 'is not divisible by 0.5' | |
end | |
it "does not add an error when #{attribute} is divisible by 0.5" do | |
subject.send("#{attribute}=", 1.5) | |
subject.validate | |
expect(subject.errors.messages[attribute]).to have(0).items | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment