Class: FeatureBehavior::Formatter

Inherits:
RSpec::Core::Formatters::DocumentationFormatter
  • Object
show all
Defined in:
lib/feature_behavior/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Formatter

Returns a new instance of Formatter.



23
24
25
26
27
28
29
30
31
# File 'lib/feature_behavior/formatter.rb', line 23

def initialize(output)
  super
  @current_behavior = ""
  @current_behavior_step = 0
  @current_description = ""
  @multi_step_example = false
  @skipped_behaviors = []
  @total_behaviors = 0
end

Instance Attribute Details

#current_behaviorObject (readonly)

Returns the value of attribute current_behavior.



15
16
17
# File 'lib/feature_behavior/formatter.rb', line 15

def current_behavior
  @current_behavior
end

#current_behavior_stepObject (readonly)

Returns the value of attribute current_behavior_step.



15
16
17
# File 'lib/feature_behavior/formatter.rb', line 15

def current_behavior_step
  @current_behavior_step
end

#current_descriptionObject (readonly)

Returns the value of attribute current_description.



15
16
17
# File 'lib/feature_behavior/formatter.rb', line 15

def current_description
  @current_description
end

#multi_step_exampleObject (readonly)

Returns the value of attribute multi_step_example.



15
16
17
# File 'lib/feature_behavior/formatter.rb', line 15

def multi_step_example
  @multi_step_example
end

#skipped_behaviorsObject (readonly)

Returns the value of attribute skipped_behaviors.



15
16
17
# File 'lib/feature_behavior/formatter.rb', line 15

def skipped_behaviors
  @skipped_behaviors
end

#total_behaviorsObject (readonly)

Returns the value of attribute total_behaviors.



15
16
17
# File 'lib/feature_behavior/formatter.rb', line 15

def total_behaviors
  @total_behaviors
end

Instance Method Details

#behavior_passed(_notification) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/feature_behavior/formatter.rb', line 33

def behavior_passed(_notification)
  msg = "#{step}#{current_behavior}"

  if current_behavior_step == 1
    output.puts "#{step_indent}#{"-" * msg.length}"
  end

  @last_msg = msg
  output.puts colorized("#{step_indent}#{msg}", :success)
end

#behavior_skipped(notification) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/feature_behavior/formatter.rb', line 44

def behavior_skipped(notification)
  @skipped_behaviors << notification
  msg = "#{step}SKIPPED: #{current_behavior}"

  if current_behavior_step == 1
    output.puts "#{step_indent}#{"-" * msg.length}"
  end

  @last_msg = msg
  output.puts colorized("#{step_indent}#{msg}", :blue)
end

#behavior_started(notification) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/feature_behavior/formatter.rb', line 56

def behavior_started(notification)
  @total_behaviors += 1
  @current_behavior = notification
  @current_behavior_step += 1

  if current_behavior_step == 1
    @multi_step_example = true
    msg = "#{current_description}, multiple steps:"
    output.puts "#{current_indentation}#{msg}"
  end
end

#behavior_terminated(_notification) ⇒ Object



68
69
# File 'lib/feature_behavior/formatter.rb', line 68

def behavior_terminated(_notification)
end

#dump_pending(notification) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/feature_behavior/formatter.rb', line 71

def dump_pending(notification)
  super

  if @skipped_behaviors.length > 0
    msg = "\nBehaviors Pending: " \
      "(Behaviors listed here have been intentionally skipped pending attention)"
    @output << msg

    results = []

    @skipped_behaviors.each_with_index do |behavior, index|
      results << skipped_behavior_dump_string(behavior, index)
    end

    @output << colorized("\n#{results.join("\n")}\n", :blue)
  end
end

#dump_summary(notification) ⇒ Object



89
90
91
92
# File 'lib/feature_behavior/formatter.rb', line 89

def dump_summary(notification)
  behavior_summary if @total_behaviors > 0
  super
end

#example_failed(_notification) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/feature_behavior/formatter.rb', line 94

def example_failed(_notification)
  if multi_step_example
    msg = "#{step}#{current_behavior} (Failed)"
    output.puts colorized("#{step_indent}#{msg}", :failure)
    output.puts "#{step_indent}#{"-" * msg.length}"
    reset_behavior
  end
  super
end

#example_passed(_notification) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/feature_behavior/formatter.rb', line 104

def example_passed(_notification)
  if multi_step_example
    output.puts "#{step_indent}#{"-" * @last_msg.length}"
    reset_behavior
  end
  super
end

#example_started(notification) ⇒ Object



112
113
114
115
116
117
# File 'lib/feature_behavior/formatter.rb', line 112

def example_started(notification)
  @current_behavior = ""
  @current_behavior_step = 0
  @current_description = notification.example.description
  super
end