Skip to content

Instantly share code, notes, and snippets.

@Prevole
Created November 14, 2011 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prevole/1363379 to your computer and use it in GitHub Desktop.
Save Prevole/1363379 to your computer and use it in GitHub Desktop.
Shoulda-Matchers + RSpec
require ".../mymodel"
FactoryGirl.define do
factory :mymodel, :class => MyModel do |m|
end
end
class MyModel < ActiveRecord::Base
validates :name, :presence => true, :format => { :with => /^(?:[a-zA-Z][a-zA-Z0-9]*)+(?:[\-_.][a-zA-Z][a-zA-Z0-9]*)*$/ }, :length => { :maximum => 255 }
end
end
describe MyModel do
describe "something relevant" do
subject { Factory.build(:mymodel) } # This model is an empty one. See the factory below
it "does have a name" do
should validate_presence_of(:name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment