Class: Docspec::Example

Inherits:
Object
  • Object
show all
Includes:
OutputCapturer
Defined in:
lib/docspec/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OutputCapturer

#capture_output

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

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/docspec/example.rb', line 7

def code
  @code
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/docspec/example.rb', line 7

def type
  @type
end

Instance Method Details

#actualObject



21
22
23
# File 'lib/docspec/example.rb', line 21

def actual
  @actual ||= actual!
end

#diffObject



29
30
31
# File 'lib/docspec/example.rb', line 29

def diff
  Diffy::Diff.new(expected, actual, context: 2).to_s :color
end

#expectedObject



17
18
19
# File 'lib/docspec/example.rb', line 17

def expected
  @expected ||= code.scan(/#=>\s*(.*)/).map { |match| match.first.strip }.join "\n"
end

#labelObject



13
14
15
# File 'lib/docspec/example.rb', line 13

def label
  @label ||= label!
end

#passing?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/docspec/example.rb', line 25

def passing?
  actual == expected
end