dm-rspec (RSpec matchers for DataMapper)

by Potapov Sergey (aka Blake)

A set of rspec matchers to test DataMapper models like you test ActiveRecord models with rspec-rails.

Installation

gem install dm-rspec

Usage

Add the next to your spec_helper:

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:

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

class Author
  include DataMapper::Resource

  property :id, Serial

  has n, :books
end

class Genre
  include DataMapper::Resource

  property :id  , Serial
  property :name, String

  has n, :books, :through => Resource
end

You specs can contain the next:

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:

Contributing to dm-rspec

Credits

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see www.gnu.org/licenses/lgpl.txt