Created
March 27, 2015 09:45
-
-
Save amyroi/627c54615002e05edcb0 to your computer and use it in GitHub Desktop.
This file contains 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
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