Sha256: 4830286ea53623c3ebcd754eae533df6ef10ec5dff29282e0fb4bc902cdbec3d

Contents?: true

Size: 968 Bytes

Versions: 7

Compression:

Stored size: 968 Bytes

Contents

module RSpec
  module Matchers
    class Exist
      include BaseMatcher

      def initialize(*args)
        super(args)
      end

      def matches?(actual)
        super(actual)
        predicates = [:exist?, :exists?].select { |p| actual.respond_to?(p) }
        existance_values = predicates.map { |p| actual.send(p, *expected) }
        uniq_truthy_values = existance_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; existance_values.first
        else raise "#exist? and #exists? returned different values:\n\n" +
          " exist?: #{existance_values.first}\n" +
          "exists?: #{existance_values.last}"
        end
      end
    end

    # Passes if `actual.exist?` or `actual.exists?`
    #
    # @example
    #   File.should exist("path/to/file")
    def exist(*args)
      Exist.new(*args)
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/exist.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/rspec-expectations-2.8.0/lib/rspec/matchers/exist.rb
horseman-0.0.4 vendor/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/matchers/exist.rb
horseman-0.0.3 vendor/ruby/1.9.1/gems/rspec-expectations-2.8.0/lib/rspec/matchers/exist.rb
rspec-expectations-2.8.0 lib/rspec/matchers/exist.rb
rspec-expectations-2.8.0.rc2 lib/rspec/matchers/exist.rb
rspec-expectations-2.8.0.rc1 lib/rspec/matchers/exist.rb