Class: Spec::Matchers::Be
Overview
:nodoc:
Instance Method Summary collapse
- #<(expected) ⇒ Object
- #<=(expected) ⇒ Object
- #==(expected) ⇒ Object
- #===(expected) ⇒ Object
- #>(expected) ⇒ Object
- #>=(expected) ⇒ Object
- #description ⇒ Object
- #expected ⇒ Object
- #failure_message ⇒ Object
-
#initialize(*args) ⇒ Be
constructor
A new instance of Be.
- #match_or_compare ⇒ Object
- #matches?(actual) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(*args) ⇒ Be
Returns a new instance of Be.
5 6 7 8 9 |
# File 'lib/spec/matchers/be.rb', line 5 def initialize(*args) @expected = parse_expected(args.shift) @args = args @comparison = "" end |
Instance Method Details
#<(expected) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/spec/matchers/be.rb', line 79 def <(expected) @less_than = true @comparison = "< " @expected = expected self end |
#<=(expected) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/spec/matchers/be.rb', line 86 def <=(expected) @less_than_or_equal = true @comparison = "<= " @expected = expected self end |
#==(expected) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/spec/matchers/be.rb', line 65 def ==(expected) @double_equal = true @comparison = "== " @expected = expected self end |
#===(expected) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/spec/matchers/be.rb', line 72 def ===(expected) @triple_equal = true @comparison = "=== " @expected = expected self end |
#>(expected) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/spec/matchers/be.rb', line 100 def >(expected) @greater_than = true @comparison = "> " @expected = expected self end |
#>=(expected) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/spec/matchers/be.rb', line 93 def >=(expected) @greater_than_or_equal = true @comparison = ">= " @expected = expected self end |
#description ⇒ Object
107 108 109 |
# File 'lib/spec/matchers/be.rb', line 107 def description "#{prefix_to_sentence}#{comparison}#{expected_to_sentence}#{args_to_sentence}" end |
#expected ⇒ Object
45 46 47 48 49 50 |
# File 'lib/spec/matchers/be.rb', line 45 def expected return true if @expected == :true return false if @expected == :false return "nil" if @expected == :nil return @expected.inspect end |
#failure_message ⇒ Object
35 36 37 38 |
# File 'lib/spec/matchers/be.rb', line 35 def return "expected #{@comparison}#{expected}, got #{@actual.inspect}" unless handling_predicate? return "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}" end |
#match_or_compare ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/spec/matchers/be.rb', line 52 def match_or_compare return @actual == true if @expected == :true return @actual == false if @expected == :false return @actual.nil? if @expected == :nil return @actual < @expected if @less_than return @actual <= @expected if @less_than_or_equal return @actual >= @expected if @greater_than_or_equal return @actual > @expected if @greater_than return @actual == @expected if @double_equal return @actual === @expected if @triple_equal return @actual.equal?(@expected) end |
#matches?(actual) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/spec/matchers/be.rb', line 11 def matches?(actual) @actual = actual return true if match_or_compare unless handling_predicate? if handling_predicate? begin return @result = actual.__send__(predicate, *@args) rescue => predicate_error # This clause should be empty, but rcov will not report it as covered # unless something (anything) is executed within the clause rcov_error_report = "http://eigenclass.org/hiki.rb?rcov-0.8.0" end # This supports should_exist > target.exists? in the old world. # We should consider deprecating that ability as in the new world # you can't write "should exist" unless you have your own custom matcher. begin return @result = actual.__send__(present_tense_predicate, *@args) rescue raise predicate_error end end return false end |
#negative_failure_message ⇒ Object
40 41 42 43 |
# File 'lib/spec/matchers/be.rb', line 40 def return "expected not #{expected}, got #{@actual.inspect}" unless handling_predicate? return "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}" end |