Module: SpecSelectorUtil::Instructions

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

Overview

The Instructions module contains methods used to render the appropriate user instructions.

Instance Method Summary collapse

Instance Method Details

#all_passed_message ⇒ Object



13
14
15
# File 'lib/spec_selector/instructions.rb', line 13

def all_passed_message
  bold("ALL EXAMPLES PASSED\n")
end

#back_instructions ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/spec_selector/instructions.rb', line 37

def back_instructions
  back_inst = 'Press [backspace] to view to parent group list'
  escape_inst = 'Press [escape] to view to top-level group list'

  [back_inst, escape_inst].each do |inst|
    if @instructions
      bold(inst)
      empty_line
    else
      @output.puts inst
    end
  end
end

#basic_instructions ⇒ Object



7
8
9
10
11
# File 'lib/spec_selector/instructions.rb', line 7

def basic_instructions
  i_for_instructions
  up_down_select_instructions
  q_to_exit
end

#display_filter_mode ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/spec_selector/instructions.rb', line 27

def display_filter_mode
  return if @inclusion_filter.empty?

  notice = "FILTER MODE: #{@filter_mode.to_s.upcase}"
  col = term_width / 2 - notice.length / 2
  position_cursor(1, col)
  italicize notice
  reset_cursor
end

#empty_filter_notice ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/spec_selector/instructions.rb', line 17

def empty_filter_notice
  notice = '**********FILTER EMPTY**********'
  row = term_width / 2 - notice.length / 2
  position_cursor(1, row)
  @output.puts notice
  reset_cursor

  nil
end

#example_summary_instructions ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'lib/spec_selector/instructions.rb', line 148

def example_summary_instructions
  i_for_instructions
  @output.puts 'Press M to remove from filter' if @selected.[:include]
  @output.puts 'Press C to clear filter' unless @inclusion_filter.empty?
  top_fail_text unless @failed.empty? || @selected == @failed.first
  back_instructions
  q_to_exit
  empty_line
end

#exit_instruction_page ⇒ Object



141
142
143
144
145
146
# File 'lib/spec_selector/instructions.rb', line 141

def exit_instruction_page
  return unless @instructions

  @instructions = false
  close_alt_buffer
end

#filter_pass_instructions ⇒ Object



60
61
62
63
# File 'lib/spec_selector/instructions.rb', line 60

def filter_pass_instructions
  verb = @exclude_passing ? 'show' : 'hide'
  bold "Press P to #{verb} passing examples in current set"
end

#i_for_instructions ⇒ Object



65
66
67
# File 'lib/spec_selector/instructions.rb', line 65

def i_for_instructions
  @output.puts 'Press I to view full instructions'
end

#q_to_exit ⇒ Object



51
52
53
# File 'lib/spec_selector/instructions.rb', line 51

def q_to_exit
  @output.puts 'Press Q to exit'
end

#toggle_instructions ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/spec_selector/instructions.rb', line 127

def toggle_instructions
  unless @instructions
    view_instructions_page
    return
  end

  exit_instruction_page_only
end

#top_fail_text ⇒ Object



136
137
138
139
# File 'lib/spec_selector/instructions.rb', line 136

def top_fail_text
  text = 'Press [spacebar] to view top failed example'
  @instructions ? bold(text) : @output.puts(text)
end

#up_down_select_instructions ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/spec_selector/instructions.rb', line 69

def up_down_select_instructions
  up_down_inst = 'Press ↑ or ↓ to navigate list'
  select_inst = 'press [enter] to select'
  instructions_text = [select_inst]
  instructions_text.unshift(up_down_inst) if @list.count > 1

  instructions_text.each do |inst|
    if @instructions
      bold(inst)
      empty_line
    else
      @output.puts inst
    end
  end
end

#view_instructions_page ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/spec_selector/instructions.rb', line 85

def view_instructions_page
  @instructions = true
  open_alt_buffer

  unless @failed.empty? || @selected == @failed.first
    top_fail_text
    empty_line
  end

  unless all_passing? || none_passing?
    filter_pass_instructions
    empty_line
  end

  up_down_select_instructions
  back_instructions unless top_level?
  bold('Press R to rerun examples with filter selection')
  empty_line
  bold('Press F to rerun only failed examples')
  empty_line
  bold('Press T to rerun only the top failed example')
  empty_line
  bold('Press M to include or remove selected item from run filter')
  empty_line

  if @inclusion_filter.size.positive?
    bold('Press C to clear filter')
    empty_line
    bold('Press A to clear filter and rerun all examples')
    empty_line
  end

  bold('Press E to view stderr log')
  empty_line
  bold('Press O to view stdout log')
  empty_line
  bold('Press I to exit instructions')
  empty_line
  bold('Press Q to quit')
  bind_input
end

#view_other_examples(status) ⇒ Object



55
56
57
58
# File 'lib/spec_selector/instructions.rb', line 55

def view_other_examples(status)
  verb = (status == :passed ? 'passing' : status.to_s)
  @output.puts "Press ↑ or ↓ to view other #{verb} examples"
end