Sha256: bd65bc1e9d3ab31924466f6c39c94f2bae2a3c2a7b4dcdf3ccfe783e6ecc3b87

Contents?: true

Size: 728 Bytes

Versions: 10

Compression:

Stored size: 728 Bytes

Contents

module DataMapper
  module Matchers
    class HaveOne
      def initialize(child)
        @child = child
      end

      def matches?(parent)
        parent_class = parent.is_a?(Class) ? parent : parent.class
        relation = parent_class.relationships[@child.to_s]

        relation and
        relation.is_a?(DataMapper::Associations::OneToOne::Relationship) and
        relation.parent_model == parent_class
      end

      def failure_message
        "expected to have one #{@child}"
      end

      def negative_failure_message
        "expected not to have one #{@child}"
      end

      def description
        "has one #{@child}"
      end
    end

    def have_one(name)
      HaveOne.new(name)
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
dm-rspec-0.2.4 lib/dm/matchers/have_one.rb
dm-rspec2-0.3.0 lib/dm/matchers/have_one.rb
dm-rspec-0.2.3 lib/dm/matchers/have_one.rb
dm-rspec-0.2.2 lib/dm/matchers/have_one.rb
dm-rspec2-0.2.4 lib/dm/matchers/have_one.rb
dm-rspec2-0.2.3 lib/dm/matchers/have_one.rb
dm-rspec2-0.2.2 lib/dm/matchers/have_one.rb
dm-rspec2-0.2.1 lib/dm/matchers/have_one.rb
dm-rspec-0.2.1 lib/dm/matchers/have_one.rb
dm-rspec-0.2.0 lib/dm/matchers/have_one.rb