Sha256: 0b7f2a5a3074e9a3eaa76e5f0bd9f010a2fc2d2544b410a23c831564090a5ace

Contents?: true

Size: 870 Bytes

Versions: 16

Compression:

Stored size: 870 Bytes

Contents

module RSpec
  module Matchers
    module BuiltIn
      class Exist < BaseMatcher
        def initialize(*expected)
          @expected = expected
        end

        def matches?(actual)
          @actual = actual
          predicates = [:exist?, :exists?].select { |p| @actual.respond_to?(p) }
          existence_values = predicates.map { |p| @actual.send(p, *@expected) }
          uniq_truthy_values = existence_values.map { |v| !!v }.uniq

          case uniq_truthy_values.size
          when 0; raise NoMethodError.new("#{@actual.inspect} does not respond to either #exist? or #exists?")
          when 1; existence_values.first
          else raise "#exist? and #exists? returned different values:\n\n" +
            " exist?: #{existence_values.first}\n" +
            "exists?: #{existence_values.last}"
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/lib/rspec/matchers/built_in/exist.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/lib/rspec/matchers/built_in/exist.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/lib/rspec/matchers/built_in/exist.rb
remq-0.0.4 vendor/bundle/gems/rspec-expectations-2.12.1/lib/rspec/matchers/built_in/exist.rb
remq-0.0.3 vendor/bundle/gems/rspec-expectations-2.12.1/lib/rspec/matchers/built_in/exist.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/lib/rspec/matchers/built_in/exist.rb
rspec-expectations-2.12.1 lib/rspec/matchers/built_in/exist.rb
rspec-expectations-2.12.0 lib/rspec/matchers/built_in/exist.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/lib/rspec/matchers/built_in/exist.rb
gem_repackager-0.1.0 support/gems/rspec-expectations-2.11.2/lib/rspec/matchers/built_in/exist.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/lib/rspec/matchers/built_in/exist.rb
rspec-expectations-2.11.3 lib/rspec/matchers/built_in/exist.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/lib/rspec/matchers/built_in/exist.rb
rspec-expectations-2.11.2 lib/rspec/matchers/built_in/exist.rb
rspec-expectations-2.11.1 lib/rspec/matchers/built_in/exist.rb
rspec-expectations-2.11.0 lib/rspec/matchers/built_in/exist.rb