Class: Spec::Matchers::Has

Inherits:
Object show all
Defined in:
lib/spec/matchers/has.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected, *args, &block) ⇒ Has

Returns a new instance of Has



6
7
8
# File 'lib/spec/matchers/has.rb', line 6

def initialize(expected, *args, &block)
  @expected, @args, @block = expected, args, block
end

Instance Method Details

#descriptionObject



22
23
24
# File 'lib/spec/matchers/has.rb', line 22

def description
  "have key #{@args[0].inspect}"
end

#failure_message_for_shouldObject



14
15
16
# File 'lib/spec/matchers/has.rb', line 14

def failure_message_for_should
  "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return true, got false"
end

#failure_message_for_should_notObject



18
19
20
# File 'lib/spec/matchers/has.rb', line 18

def failure_message_for_should_not
  "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return false, got true"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/spec/matchers/has.rb', line 10

def matches?(actual)
  actual.__send__(predicate(@expected), *@args, &@block)
end