Skip to content

Instantly share code, notes, and snippets.

@evolve2k
Created November 13, 2009 04:38
Show Gist options
  • Save evolve2k/233591 to your computer and use it in GitHub Desktop.
Save evolve2k/233591 to your computer and use it in GitHub Desktop.
#Rspec code for the tutorial RSpec Rails tutorial
#Developing a Rails model using BDD and RSpec, Part 1 (by Luke Redpath)
#http://lukeredpath.co.uk/blog/developing-a-rails-model-using-bdd-and-rspec-part-1.html
#Code updated based on my understanding of the current versions and convetions of RSpec in 2009.
require 'spec_helper'
describe User do
before(:each) do
end
it "should be invalid without a username" do
@user = User.new
@user.should_not be_valid
@user.errors.on(:username).should == "is required"
@user.username = 'someusername'
@user.should be_valid
end
it "should be invalid without an email" do
@user.should_not be_valid
@user.errors.on(:email).should == "is required"
@user.email = 'joe@bloggs.com'
@user.should be_valid
end
it "should be invalid without a password" do
@user.attributes = valid_user_attributes.except(:password)
@user.should_not be_valid
@user.errors.on(:password).should == "is required"
@user.password = 'badpassword'
@user.should be_valid
end
it "should be invalid if password is not between 6-12 characters in length" do
@user.attributes = valid_user_attributes.except(:password)
@user.password = "1234567890123"
@user.should_not be_valid
@user.password = '12345'
@user.should_not be_valid
@user.password = '1234567'
@user.should be_valid
end
it "should have an encrypted password"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment