Class: Spec::Matchers::Has

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

Instance Method Summary (collapse)

Constructor Details

- (Has) initialize(expected, *args, &block)

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

- (Object) description



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

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

- (Object) failure_message_for_should



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

- (Object) failure_message_for_should_not



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

- (Boolean) matches?(actual)

Returns:

  • (Boolean)


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

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