Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.