Created
September 7, 2011 21:35
-
-
Save jaysonrowe/1201825 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
describe User do | |
before(:each) do | |
@attr = { :name => "Example User", :email => "[email protected]" } | |
end | |
it "should create a new instance given valid attributes" do | |
User.create!(@attr) | |
end | |
it "should require a name" do | |
no_name_user = User.new(@attr.merge(:name => "")) | |
no_name_user.should_not be_valid | |
end | |
end | |
it "should require an email address" do | |
no_email_user = User.new(@attr.merge(:email => "")) | |
no_email_user.should_not be_valid | |
end | |
end | |
it "should reject names that are too long" do | |
long_name = "a" * 51 | |
long_name_user = User.new(@attr.merge(:name => long_name)) | |
long_name_user.should_not be_valid | |
end | |
end | |
it "should accept valid email addresses" do | |
addresses = %w[[email protected] [email protected] [email protected]] | |
addresses.each do |address| | |
valid_email_user = User.new(@attr.merge(:email => address)) | |
valid_email_user.should be_valid | |
end | |
end | |
it "should reject invalid email addresses" do | |
addresses = %w[user@foo,com user_at_foo.org example.user@foo.] | |
addresses.each do |address| | |
invalid_email_user = User.new(@attr.merge(:email => address)) | |
invalid_email_user.should_not be_valid | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment