README.markdown in dm-rspec-0.2.3 vs README.markdown in dm-rspec-0.2.4

- old
+ new

@@ -8,19 +8,21 @@ gem install dm-rspec ## Usage - + Add the next to your `spec_helper`: - require 'dm-rspec' - - RSpec.configure do |config| - config.include(DataMapper::Matchers) - end +```ruby +require 'dm-rspec' +RSpec.configure do |config| + config.include(DataMapper::Matchers) +end +``` + In your spec files you can use the next matchers to test appropriate DataMapper's validations: * belong\_to * have\_one * have\_many @@ -35,74 +37,93 @@ ## Examples Assume you have the next data mapper models: - class Book - include DataMapper::Resource - property :id, Serial - property :name, String - belongs_to :author - has n, :genres, :through => Resource - validates_presence_of :name - end +```ruby +class Book + include DataMapper::Resource - class Author - include DataMapper::Resource - property :id, Serial - has n, :books - end + property :id , Serial + property :name, String - class Genre - include DataMapper::Resource - property :id, Serial - property :name, String - has n, :books, :through => Resource - end + belongs_to :author + has n, :genres, :through => Resource -You specs can contain the next: + validates_presence_of :name +end - specify {Book.should have_property :name} - specify {Book.should belong_to :author} - specify {Author.should have_many :books} - specify {Genre.should have_many_and_belong_to :books} - specify {Book.should have_many_and_belong_to :genres} +class Author + include DataMapper::Resource - specify {Book.should validate_presence_of :name} + property :id, Serial - it 'has errors' do - book = Book.new(:name => 'fails on two validations') - book.valid? - book.should have(2).errors_on(:name) - end + has n, :books +end -They can look like below as well: +class Genre + include DataMapper::Resource - describe Book do - it { should have_property :name } - it { should belongs_to :author } - end + property :id , Serial + property :name, String + has n, :books, :through => Resource +end +``` +You specs can contain the next: +```ruby +describe Book do + it { should have_property :name } + it { should belong_to :author } + it { should have_many_and_belong_to :genres } + it { should validate_presence_of :name } + it 'should have errors' do + book = Book.new(:name => 'fails on two validations') + book.valid? + book.should have(2).errors_on(:name) + end +end + +describe Author do + it { should have_many :books } +end + +describe Genre do + it { should have_many_and_belong_to :books } +end +``` + + + + ## TODO Implement the next rspec matchers: * have timestamps * matchers to verify validations ## Contributing to dm-rspec - + * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it * Fork the project * Start a feature/bugfix branch * Commit and push until you are happy with your contribution * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. + +## Credits + +* [Sergey Potapov](https://github.com/greyblake) - creator and maintainer +* [Victor Deryagin](https://github.com/vderyagin) +* [George Hindle](https://github.com/ghindle) +* [Adam Meghji](https://github.com/adammeghji) +* [Gavin Joyce](https://github.com/GavinJoyce) - validate_length_of matcher ## License This program is free software: you can redistribute it and/or modify