Skip to content

Instantly share code, notes, and snippets.

@amyroi
Created March 27, 2015 09:45
Show Gist options
  • Save amyroi/627c54615002e05edcb0 to your computer and use it in GitHub Desktop.
Save amyroi/627c54615002e05edcb0 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe MyModel do
it "should create a new instance given valid attributes" do
Factory(:my_model)
end
describe "name" do
it "should be required" do
blank = Factory.build(:my_model, :name => "")
expect(blank).to_not be_valid
expect(blank.errors[:name]).to include("can't be blank")
blank.name = "Foo"
expect(blank).to be_valid
end
it "should be longer than 1 character" do
too_short = Factory.build(:my_model, :name => 'a')
expect(too_short).to_not be_valid
expect(too_short.errors[:name]).to include("is too short (minimum is 2 characters)")
too_short.name = 'aa'
expect(too_short).to be_valid
end
it "should be shorter than 101 characters" do
too_long = Factory.build(:my_model, :name => 'a' * 101)
expect(too_long).to_not be_valid
expect(too_long.errors[:name]).to include("is too long (maximum is 100 characters)")
too_long.name = 'a' * 100
expect(too_long).to be_valid
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment