Skip to content

Instantly share code, notes, and snippets.

@aldesantis
Last active January 24, 2016 17:25
Show Gist options
  • Save aldesantis/bded51a0e0449d94f769 to your computer and use it in GitHub Desktop.
Save aldesantis/bded51a0e0449d94f769 to your computer and use it in GitHub Desktop.
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