Class: Spec::Matchers::BePredicate

Inherits:
Be show all
Defined in:
lib/spec/matchers/be.rb

Instance Method Summary collapse

Methods included from Pretty

#_pretty_print, #split_words, #to_sentence

Constructor Details

#initialize(*args, &block) ⇒ BePredicate

Returns a new instance of BePredicate.


121
122
123
124
125
# File 'lib/spec/matchers/be.rb', line 121

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

Instance Method Details

#descriptionObject


150
151
152
# File 'lib/spec/matchers/be.rb', line 150

def description
  "#{prefix_to_sentence}#{expected_to_sentence}#{args_to_sentence}"
end

#failure_message_for_shouldObject


142
143
144
# File 'lib/spec/matchers/be.rb', line 142

def failure_message_for_should
  "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
end

#failure_message_for_should_notObject


146
147
148
# File 'lib/spec/matchers/be.rb', line 146

def failure_message_for_should_not
  "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)

127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/spec/matchers/be.rb', line 127

def matches?(actual)
  @actual = actual
  begin
    return @result = actual.__send__(predicate, *@args, &@block)
  rescue NameError => predicate_missing_error
    "this needs to be here or rcov will not count this branch even though it's executed in a code example"
  end

  begin
    return @result = actual.__send__(present_tense_predicate, *@args, &@block)
  rescue NameError
    raise predicate_missing_error
  end
end