Created
November 14, 2011 06:26
-
-
Save Prevole/1363379 to your computer and use it in GitHub Desktop.
Shoulda-Matchers + RSpec
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 ".../mymodel" | |
FactoryGirl.define do | |
factory :mymodel, :class => MyModel do |m| | |
end | |
end |
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
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 |
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
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