Class: RSpec::Matchers::BuiltIn::Has

Inherits:
Object
  • Object
show all
Includes:
MatchAliases
Defined in:
lib/rspec/matchers/built_in/has.rb

Instance Method Summary (collapse)

Methods included from MatchAliases

#==, #===

Constructor Details

- (Has) initialize(expected, *args)

A new instance of Has

7
8
9
# File 'lib/rspec/matchers/built_in/has.rb', line 7
def initialize(expected, *args)
  @expected, @args = expected, args
end

Instance Method Details

- (Object) description

32
33
34
# File 'lib/rspec/matchers/built_in/has.rb', line 32
def description
  [method_description(@expected), args_description].compact.join(' ')
end

- (Object) failure_message_for_should

24
25
26
# File 'lib/rspec/matchers/built_in/has.rb', line 24
def failure_message_for_should
  "expected ##{predicate}#{failure_message_args_description} to return true, got false"
end

- (Object) failure_message_for_should_not

28
29
30
# File 'lib/rspec/matchers/built_in/has.rb', line 28
def failure_message_for_should_not
  "expected ##{predicate}#{failure_message_args_description} to return false, got true"
end

- (Boolean) is_private_on?(actual)

Returns:

  • (Boolean)
45
46
47
# File 'lib/rspec/matchers/built_in/has.rb', line 45
def is_private_on? actual
  actual.private_methods.include? predicate.to_s
end

- (Boolean) matches?(actual)

Returns:

  • (Boolean)
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rspec/matchers/built_in/has.rb', line 11
def matches?(actual)
  method = predicate
  if is_private_on?(actual)
    RSpec.deprecate "matching with #{@expected} on private method #{predicate}",
      :replacement => "`expect(object.send(#{predicate.inspect})).to be_true` or change the method's visibility to public"
  end
  result = actual.__send__(method, *@args)
  check_respond_to(actual, method)
  result
end