Module: SpecSelectorUtil::DataPresentation

Included in:
SpecSelector
Defined in:
lib/spec_selector/data_presentation.rb

Overview

The DataPresentation module contains methods used to render mapped data.

Instance Method Summary collapse

Instance Method Details

#display_example ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/spec_selector/data_presentation.rb', line 155

def display_example
  @example_display = true
  clear_frame
  display_filter_mode
  test_data_summary
  status = @selected.execution_result.status
  @list, data = example_list
  example_summary_instructions
  @output.puts 'Added to filter √' if @selected.[:include]
  @selector_index = @list.index(@selected)
  view_other_examples(status) if @list.count > 1 && @instructions
  format_example(status, data)
end

#display_list ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/spec_selector/data_presentation.rb', line 116

def display_list
  clear_frame
  display_filter_mode
  test_data_summary
  print_messages unless @messages.empty?
  all_passed_message if all_passing?
  basic_instructions
  empty_line

  @list.each { |item| format_list_item(item) }
end

#display_stderr_log ⇒ Object



142
143
144
# File 'lib/spec_selector/data_presentation.rb', line 142

def display_stderr_log
  system("less #{stderr_log.path}")
end

#display_stdout_log ⇒ Object



146
147
148
# File 'lib/spec_selector/data_presentation.rb', line 146

def display_stdout_log
  system("less #{stdout_log.path}")
end

#errors_before_formatter_initialization ⇒ Object

If an exception is raised before an instance of SpecSelector is initialized (for instance, a TypeError raised due to a configuration problem), the MessageNotification will be sent to the registered default formatter instead and will not be accessable to SpecSelector. In such a case, the formatted error information is printed immediately in the manner determined by the default formatter. This method simply checks for a condition caused by that situation and leaves the error information displayed until the user exits.



19
20
21
22
23
24
# File 'lib/spec_selector/data_presentation.rb', line 19

def errors_before_formatter_initialization
  return unless @outside_errors_count.positive? && @messages == ['No examples found.']

  empty_line
  exit_only
end

#errors_summary(notification) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/spec_selector/data_presentation.rb', line 57

def errors_summary(notification)
  err_count = notification.errors_outside_of_examples_count
  word_form = err_count > 1 ? 'errors' : 'error'
  italicize "Finished in #{notification.duration} seconds"
  italicize "Files loaded in #{notification.load_time}"
  empty_line
  italicize "#{err_count} #{word_form} occurred outside of examples"
  italicize 'Examples were not successfully executed'
  exit_only
end

#example_list ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/spec_selector/data_presentation.rb', line 169

def example_list
  status = @selected.execution_result.status
  result_list = @failed if status == :failed
  result_list = @pending if status == :pending
  result_list = @passed if status == :passed

  data = @failure_summaries[@selected] if status == :failed
  data = @pending_summaries[@selected] if status == :pending

  [result_list, data]
end

#examples_summary(notification) ⇒ Object



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

def examples_summary(notification)
  @summary_notification = notification
  status_summary(notification)

  @list = if @inclusion_filter.empty? || @inclusion_filter.count > 10
            @map[:top_level]
          else
            @inclusion_filter
          end

  selector
end

#exclude_passing! ⇒ Object



80
81
82
83
84
85
# File 'lib/spec_selector/data_presentation.rb', line 80

def exclude_passing!
  alt_map = @map.reject { |_, v| v.all? { |g| all_passed?(fetch_examples(g)) } }
  alt_map.transform_values! { |v| v.reject { |g| all_passed?(fetch_examples(g)) } }
  @active_map = alt_map
  @exclude_passing = true
end

#include_passing! ⇒ Object



87
88
89
90
# File 'lib/spec_selector/data_presentation.rb', line 87

def include_passing!
  @active_map = @map
  @exclude_passing = false
end

#messages_only ⇒ Object



181
182
183
184
185
# File 'lib/spec_selector/data_presentation.rb', line 181

def messages_only
  clear_frame
  print_messages
  exit_only
end


26
27
28
29
30
# File 'lib/spec_selector/data_presentation.rb', line 26

def print_errors(notification)
  clear_frame
  print_messages
  errors_summary(notification)
end


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/spec_selector/data_presentation.rb', line 32

def print_messages
  printed = 0
  @messages.each do |message|
    next if message.include?('Run options: include {:full_description=>')
    next if message.include?('Run options: include {:locations=>')

    italicize(message)
    printed += 1
  end
  empty_line if printed.positive?
end


75
76
77
78
# File 'lib/spec_selector/data_presentation.rb', line 75

def print_summary
  @summary.each { |sum| italicize(sum) }
  empty_line
end

#refresh_display ⇒ Object



150
151
152
153
# File 'lib/spec_selector/data_presentation.rb', line 150

def refresh_display
  set_selected
  @example_display ? display_example : display_list
end

#status_count ⇒ Object



68
69
70
71
72
73
# File 'lib/spec_selector/data_presentation.rb', line 68

def status_count
  pass_count
  pending_count if @pending_count.positive?
  fail_count
  empty_line
end

#status_summary(notification) ⇒ Object



109
110
111
112
113
114
# File 'lib/spec_selector/data_presentation.rb', line 109

def status_summary(notification)
  @summary = []
  @summary << "Total Examples: #{@example_count}"
  @summary << "Finished in #{notification.duration} seconds"
  @summary << "Files loaded in #{notification.load_time} seconds"
end

#test_data_summary ⇒ Object



6
7
8
9
# File 'lib/spec_selector/data_presentation.rb', line 6

def test_data_summary
  status_count
  print_summary
end

#toggle_passing ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/spec_selector/data_presentation.rb', line 92

def toggle_passing
  return if all_passing?

  @exclude_passing ? include_passing! : exclude_passing!
  return if @example_display && @list != @passed && !@instructions

  exit_instruction_page
  p_data = parent_data(@selected.)
  key = p_data ? p_data[:block] : :top_level
  new_list = @active_map[key]
  @list = new_list
  @selected = nil
  @example_display = false
  set_selected
  display_list
end

#view_inclusion_filter ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/spec_selector/data_presentation.rb', line 128

def view_inclusion_filter
  if @inclusion_filter.empty?
    empty_filter_notice
    return
  end

  @example_display = false
  exit_instruction_page if @instructions
  @list = @inclusion_filter
  @selected = @list.first unless @selected.[:include]
  set_selected
  display_list
end