123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Matchers::BuiltIn::Exist::ExistenceTest Private

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Struct
Instance Chain:
self, Struct
Inherits: Struct
  • Object
Defined in: rspec-expectations/lib/rspec/matchers/built_in/exist.rb

Overview

Simple class for memoizing actual/expected for this matcher and examining the match

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#actual (rw)

Simple class for memoizing actual/expected for this matcher and examining the match

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 43

class ExistenceTest < Struct.new(:actual, :expected)

#actual_exists?Boolean (readonly)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 52

def actual_exists?
  existence_values.first
end

#expected (rw)

Simple class for memoizing actual/expected for this matcher and examining the match

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 43

class ExistenceTest < Struct.new(:actual, :expected)

#valid_test?Boolean (readonly)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 46

def valid_test?
  uniq_truthy_values.size == 1
end

Instance Method Details

#deprecated(predicate, actual) (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 83

def deprecated(predicate, actual)
  predicate == :exists? && (File == actual || FileTest == actual || Dir == actual)
end

#existence_values (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 75

def existence_values
  @existence_values ||= predicates.map { |p| actual.__send__(p, *expected) }
end

#predicates (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 79

def predicates
  @predicates ||= [:exist?, :exists?].select { |p| actual.respond_to?(p) && !deprecated(p, actual) }
end

#uniq_truthy_values (private)

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 71

def uniq_truthy_values
  @uniq_truthy_values ||= existence_values.map { |v| !!v }.uniq
end

#validity_messageString

[ GitHub ]

  
# File 'rspec-expectations/lib/rspec/matchers/built_in/exist.rb', line 58

def validity_message
  case uniq_truthy_values.size
  when 0
    " but it does not respond to either `exist?` or `exists?`"
  when 2
    " but `exist?` and `exists?` returned different values:\n\n"\
    " exist?: #{existence_values.first}\n"\
    "exists?: #{existence_values.last}"
  end
end