Sha256: b598c890b6813bcad215224f464a119bf1cf3f42eb857a2d7309e0dcda1fc7b9

Contents?: true

Size: 1.4 KB

Versions: 87

Compression:

Stored size: 1.4 KB

Contents

# RSpec matcher to spec delegations.

RSpec::Matchers.define :have_predicate do |predicate|
  match do |subject|
    @predicate = predicate
    if @predicate.nil? || !@expected_objects.respond_to?(:count)
      raise(
        ArgumentError,
        "expect(subject).to have_predicate(<predicate>).with_objects(<objects[]>)"
      )
    end
    @subject = subject.class.find(subject.id)
    @actual_objects = @subject.relationships(predicate)

    if @expected_objects
      actual_count = @actual_objects.count
      expected_count = @expected_objects.count
      if actual_count != expected_count
        raise(
          RSpec::Expectations::ExpectationNotMetError,
          "#{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} count <Expected Count: #{expected_count}> <Actual: #{actual_count}>"
        )
      end
      intersection = @actual_objects & @expected_objects

      intersection.count == @expected_objects.count
    end
  end

  chain(:with_objects) { |objects| @expected_objects = objects }

  description do
    "#{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} matches Fedora"
  end

  failure_message do |_text|
    "expected #{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} to match"
  end

  failure_message_when_negated do |_text|
    "expected #{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} to NOT match"
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
active-fedora-11.1.4 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.1.3 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.1.2 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.1.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.1.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-10.3.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-9.7.3 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-10.3.0.rc2 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc7 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-10.3.0.rc1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc6 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-10.2.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc5 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc4 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-10.2.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc3 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc2 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-11.0.0.rc1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb