Class: Spec::Matchers::Be
- Defined in:
- lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb
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?(given) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(*args) ⇒ Be
Returns a new instance of Be.
5 6 7 8 9 10 11 12 13 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 5 def initialize(*args) if args.empty? @expected = :satisfy_if else @expected = parse_expected(args.shift) end @args = args @comparison = "" end |
Instance Method Details
#<(expected) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 84 def <(expected) @prefix = "be " @less_than = true @comparison = "< " @expected = expected self end |
#<=(expected) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 92 def <=(expected) @prefix = "be " @less_than_or_equal = true @comparison = "<= " @expected = expected self end |
#==(expected) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 68 def ==(expected) @prefix = "be " @double_equal = true @comparison = "== " @expected = expected self end |
#===(expected) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 76 def ===(expected) @prefix = "be " @triple_equal = true @comparison = "=== " @expected = expected self end |
#>(expected) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 108 def >(expected) @prefix = "be " @greater_than = true @comparison = "> " @expected = expected self end |
#>=(expected) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 100 def >=(expected) @prefix = "be " @greater_than_or_equal = true @comparison = ">= " @expected = expected self end |
#description ⇒ Object
116 117 118 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 116 def description "#{prefix_to_sentence}#{comparison}#{expected_to_sentence}#{args_to_sentence}" end |
#expected ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 46 def expected return "if to be satisfied" if @expected == :satisfy_if return true if @expected == :true return false if @expected == :false return "nil" if @expected == :nil return @expected.inspect end |
#failure_message ⇒ Object
36 37 38 39 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 36 def return "expected #{@comparison}#{expected}, got #{@given.inspect}" unless handling_predicate? return "expected #{predicate}#{args_to_s} to return true, got #{@result.inspect}" end |
#match_or_compare ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 54 def match_or_compare return @given ? true : false if @expected == :satisfy_if return @given == true if @expected == :true return @given == false if @expected == :false return @given.nil? if @expected == :nil return @given < @expected if @less_than return @given <= @expected if @less_than_or_equal return @given >= @expected if @greater_than_or_equal return @given > @expected if @greater_than return @given == @expected if @double_equal return @given === @expected if @triple_equal return @given.equal?(@expected) end |
#matches?(given) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 15 def matches?(given) @given = given if handling_predicate? begin return @result = given.__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 begin return @result = given.__send__(present_tense_predicate, *@args) rescue raise predicate_error end else return match_or_compare end end |
#negative_failure_message ⇒ Object
41 42 43 44 |
# File 'lib/gems/rspec-1.1.11/lib/spec/matchers/be.rb', line 41 def return "expected not #{expected}, got #{@given.inspect}" unless handling_predicate? return "expected #{predicate}#{args_to_s} to return false, got #{@result.inspect}" end |