Sha256: ce8d16a9066292213423fa0fcb8d310541db459b99444a8a1e9c03a37b9b2c04

Contents?: true

Size: 1.52 KB

Versions: 76

Compression:

Stored size: 1.52 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,
        "subject.should have_predicate(<predicate>).with_objects(<objects[]>)"
      )
    end
    @subject = subject.class.find(subject.pid)
    @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} PID=#{@subject.pid} relationship: #{@predicate.inspect} count <Expected Count: #{expected_count}> <Actual: #{actual_count}>"
        )
      end
      intersection = @actual_objects.collect do |ao|
        internal_uri = ao.respond_to?(:internal_uri) ? ao.internal_uri : ao
      end & @expected_objects

      intersection.count == @expected_objects.count
    end
  end

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


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

  failure_message_for_should do |text|
    "expected #{@subject.class} PID=#{@subject.pid} relationship: #{@predicate.inspect} to match"
  end

  failure_message_for_should_not do |text|
    "expected #{@subject.class} PID=#{@subject.pid} relationship: #{@predicate.inspect} to NOT match"
  end

end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
active-fedora-8.7.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.6.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.5.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.4.2 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.4.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-7.3.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-7.3.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.4.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.3.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.2.2 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.2.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.2.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-7.2.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-6.8.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.1.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.0.1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.0.0 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.0.0.rc3 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.0.0.rc2 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb
active-fedora-8.0.0.rc1 lib/active_fedora/rspec_matchers/have_predicate_matcher.rb