spec/spec_helper.rb in dm-rspec-0.2.3 vs spec/spec_helper.rb in dm-rspec-0.2.4

- old
+ new

@@ -24,20 +24,23 @@ # helper matchers for testing dm-rspec matchers # def fail() raise_error(RSpec::Expectations::ExpectationNotMetError) end - + def fail_with(message) raise_error(RSpec::Expectations::ExpectationNotMetError,message) end class Proc include ::RSpec::Matchers def should_pass lambda { self.call }.should_not raise_error end + def should_fail + lambda { self.call }.should raise_error + end end @@ -66,11 +69,11 @@ validates_uniqueness_of :last_name end class Genre include DataMapper::Resource - property :id, Serial + property :id , Serial property :name, String has n, :books, :through => Resource validates_uniqueness_of :name, :message => 'Genre name must be unique!' validates_format_of :name, :with => /\w+/, :message => "Bad format of genre" end @@ -89,11 +92,11 @@ property :id, Serial belongs_to :tag belongs_to :book end -# To test validates_presence_of +# To test validate_presence_of class Person include DataMapper::Resource property :id, Serial property :first_name, String property :last_name , String @@ -103,9 +106,24 @@ end class Foreword include DataMapper::Resource property :id, Serial +end + +# To test validate_length_of +class Publisher + include DataMapper::Resource + property :id , Serial + property :name , String, :length => 128 + property :address, String, :length => 1024 + property :phone , String, :length => 5..15 + property :zip , String + property :city , String + + validates_length_of :address, :maximum => 2000 #This overrides the previous :length + validates_length_of :zip, :is => 6 + validates_length_of :city, :minimum => 2 end DataMapper.finalize DataMapper.auto_migrate!