Class: Docspec::Example
- Inherits:
-
Object
- Object
- Docspec::Example
- Includes:
- OutputCapturer
- Defined in:
- lib/docspec/example.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #actual ⇒ Object
- #diff ⇒ Object
- #expected ⇒ Object
-
#initialize(code, type) ⇒ Example
constructor
A new instance of Example.
- #label ⇒ Object
- #passing? ⇒ Boolean
Methods included from OutputCapturer
Constructor Details
#initialize(code, type) ⇒ Example
Returns a new instance of Example.
9 10 11 |
# File 'lib/docspec/example.rb', line 9 def initialize(code, type) @code, @type = code, type end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/docspec/example.rb', line 7 def code @code end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/docspec/example.rb', line 7 def type @type end |
Instance Method Details
#actual ⇒ Object
21 22 23 |
# File 'lib/docspec/example.rb', line 21 def actual @actual ||= actual! end |
#diff ⇒ Object
29 30 31 |
# File 'lib/docspec/example.rb', line 29 def diff Diffy::Diff.new(expected, actual, context: 2).to_s :color end |
#expected ⇒ Object
17 18 19 |
# File 'lib/docspec/example.rb', line 17 def expected @expected ||= code.scan(/#=>\s*(.*)/).map { |match| match.first.strip }.join "\n" end |
#label ⇒ Object
13 14 15 |
# File 'lib/docspec/example.rb', line 13 def label @label ||= label! end |
#passing? ⇒ Boolean
25 26 27 |
# File 'lib/docspec/example.rb', line 25 def passing? actual == expected end |