Sha256: 1920917f4663f0b189e4bf5c7c58b97f947553f5c13c02a375f544a96922ab06

Contents?: true

Size: 1.52 KB

Versions: 33

Compression:

Stored size: 1.52 KB

Contents

# RSpec matcher to spec delegations.

RSpec::Matchers.define :have_many_associated_active_fedora_objects do |association_name|
  match do |subject|
    @association_name = association_name
    if @association_name.nil? || !@expected_objects.respond_to?(:count)
      raise(
        ArgumentError,
        "expect(subject).to have_many_associated_active_fedora_objects(<association_name>).with_objects(<objects[]>)"
      )
    end

    @subject = subject.class.find(subject.id)
    @actual_objects = @subject.send(@association_name)

    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: #{@association_name.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} association: #{@association_name.inspect} matches ActiveFedora"
  end

  failure_message do |text|
    "expected #{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} to match"
  end

  failure_message_when_negated do |text|
    "expected #{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} to NOT match"
  end

end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
active-fedora-9.0.8 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.5.0 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.4.3 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.4.2 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.4.1 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.4.0 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.3.0 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.2.1 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.2.0 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.2.0.rc2 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.2.0.rc1 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.1.2 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.1.1 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.1.0 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.1.0.rc1 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.0.6 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.0.5 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.0.4 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.0.3 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb
active-fedora-9.0.2 lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb