Class: Uspec::Result
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
Instance Method Summary collapse
- #failure? ⇒ Boolean
-
#initialize(spec, raw, source) ⇒ Result
constructor
A new instance of Result.
- #inspect ⇒ Object
-
#inspector ⇒ Object
Attempts to inspect an object.
- #message ⇒ Object
- #pending! ⇒ Object
- #pending? ⇒ Boolean
- #pretty ⇒ Object
- #subklassinfo ⇒ Object
- #success? ⇒ Boolean
- #trace ⇒ Object
Methods included from Terminal
color, colors, esc, hspace, method_missing, newline, normal, vspace
Constructor Details
#initialize(spec, raw, source) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 |
# File 'lib/uspec/result.rb', line 8 def initialize spec, raw, source @spec = spec @raw = raw @source = source @handler = ::TOISB.wrap raw end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Uspec::Terminal
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
14 15 16 |
# File 'lib/uspec/result.rb', line 14 def handler @handler end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
14 15 16 |
# File 'lib/uspec/result.rb', line 14 def raw @raw end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
14 15 16 |
# File 'lib/uspec/result.rb', line 14 def source @source end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
14 15 16 |
# File 'lib/uspec/result.rb', line 14 def spec @spec end |
Instance Method Details
#failure? ⇒ Boolean
95 96 97 |
# File 'lib/uspec/result.rb', line 95 def failure? raw != true && !@pending end |
#inspect ⇒ Object
107 108 109 |
# File 'lib/uspec/result.rb', line 107 def inspect "#{self.class} for `#{spec}` -> #{pretty}" end |
#inspector ⇒ Object
Attempts to inspect an object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/uspec/result.rb', line 56 def inspector if String === raw && raw.include?(?\n) then # if object is a multiline string, display it unescaped [ vspace, hspace, yellow('"""'), newline, raw, normal, newline, hspace, yellow('"""') ].join else handler.inspector! end rescue Exception => error return handler.simple_inspector if error..include? handler.get_id error_file, error_line, _ = error.backtrace[4].split ?: <<-MSG #{error.class} : #{error.} Uspec detected a bug in your source code! Calling #inspect on an object will recusively call #inspect on its instance variables and contents. If one of those contained objects does not have an #inspect method you will see this message. You will also get this message if your #inspect method or one of its callees raises an exception. This is most likely to happen with BasicObject and its subclasses. If you think this is a bug in Uspec please report it: https://github.com/acook/uspec/issues/new Error may have occured in test `#{spec}` in file `#{error_file}` on line ##{error_line}. \t#{error.backtrace.join "\n\t"} MSG end |
#message ⇒ Object
47 48 49 |
# File 'lib/uspec/result.rb', line 47 def "#{red subklassinfo}#{raw.}" end |
#pending! ⇒ Object
103 104 105 |
# File 'lib/uspec/result.rb', line 103 def pending! @pending = true end |
#pending? ⇒ Boolean
99 100 101 |
# File 'lib/uspec/result.rb', line 99 def pending? !!@pending end |
#pretty ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/uspec/result.rb', line 16 def pretty if raw == true then green raw elsif raw == false then red raw elsif pending? then yellow 'pending' elsif Exception === raw then [ red('Exception'), vspace, hspace, 'Spec encountered an Exception ', newline, hspace, 'in spec at ', source.first, vspace, hspace, , vspace, white(trace) ].join else [ red('Failed'), vspace, hspace, 'Spec did not return a boolean value ', newline, hspace, 'in spec at ', source.first, vspace, hspace, red(subklassinfo), inspector, newline ].join end end |
#subklassinfo ⇒ Object
51 52 53 |
# File 'lib/uspec/result.rb', line 51 def subklassinfo "#{handler.subklassinfo}: " end |
#success? ⇒ Boolean
91 92 93 |
# File 'lib/uspec/result.rb', line 91 def success? raw == true end |
#trace ⇒ Object
41 42 43 44 45 |
# File 'lib/uspec/result.rb', line 41 def trace raw.backtrace.inject(String.new) do |text, line| text << "#{hspace}#{line}#{newline}" end end |