Class: Spec::Matchers::Be
Overview
Instance Method Summary
collapse
Methods included from Pretty
#_pretty_print, #split_words, #to_sentence
Constructor Details
#initialize(*args) ⇒ Be
Returns a new instance of Be.
7
8
9
10
11
|
# File 'lib/spec/matchers/be.rb', line 7
def initialize(*args)
@expected = args.empty? ? true : set_expected(args.shift)
@args = args
@comparison_method = nil
end
|
Instance Method Details
#description ⇒ Object
63
64
65
|
# File 'lib/spec/matchers/be.rb', line 63
def description
"#{prefix_to_sentence}#{comparison} #{expected_to_sentence}#{args_to_sentence}".gsub(/\s+/,' ')
end
|
#failure_message_for_should ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/spec/matchers/be.rb', line 32
def failure_message_for_should
if handling_predicate?
if predicate == :nil?
"expected nil, got #{@actual.inspect}"
else
"expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}"
end
else
"expected #{@comparison_method} #{expected}, got #{@actual.inspect}".gsub(' ',' ')
end
end
|
#failure_message_for_should_not ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/spec/matchers/be.rb', line 44
def failure_message_for_should_not
if handling_predicate?
if predicate == :nil?
"expected not nil, got nil"
else
"expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}"
end
else
message = "'should_not be \#{@comparison_method} \#{expected}' not only FAILED,\nit is a bit confusing.\n MESSAGE\n \n raise message << ([:===,:==].include?(@comparison_method) ?\n \"It might be more clearly expressed without the \\\"be\\\"?\" :\n \"It might be more clearly expressed in the positive?\")\n end\nend\n"
|
#matches?(actual) ⇒ Boolean
13
14
15
16
|
# File 'lib/spec/matchers/be.rb', line 13
def matches?(actual)
@actual = actual
handling_predicate? ? run_predicate_on(actual) : match_or_compare(actual)
end
|
#run_predicate_on(actual) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/spec/matchers/be.rb', line 18
def run_predicate_on(actual)
begin
return @result = actual.__send__(predicate, *@args)
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)
rescue NameError
raise predicate_missing_error
end
end
|