Module: SpecSelectorUtil::Format
- Included in:
- SpecSelector
- Defined in:
- lib/spec_selector/format.rb
Overview
The Format module contains methods used for simple text formatting, as well as methods that determine how specific list items will be formatted.
Constant Summary collapse
- ESCAPE_CODES =
{ green: '1;32', # the numeric codes for green, yellow, and red are red: '1;31', # 32, 31, and 33 respectively. The '1;' is prepended yellow: '1;33', # for bold lettering. italicize: 3, bold: 1 }.freeze
Instance Method Summary collapse
- #fail_count ⇒ Object
- #fetch_examples(item) ⇒ Object
- #format_example(status, data) ⇒ Object
- #format_list_item(item) ⇒ Object
- #highlight(text, included: false) ⇒ Object
- #lineage(data) ⇒ Object
- #pass_count ⇒ Object
- #pending_count ⇒ Object
- #print_nonpassing_example(data) ⇒ Object
- #print_passing_example ⇒ Object
Instance Method Details
#fail_count ⇒ Object
60 61 62 |
# File 'lib/spec_selector/format.rb', line 60 def fail_count red("FAIL: #{@fail_count}") end |
#fetch_examples(item) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/spec_selector/format.rb', line 23 def fetch_examples(item) return [item] if example?(item) examples = item.examples return examples if @map[item.[:block]] == examples examples.reject! { |ex| ex.execution_result.status.nil? } @map[item.[:block]].each do |d| examples += fetch_examples(d) end examples end |
#format_example(status, data) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/spec_selector/format.rb', line 76 def format_example(status, data) if %i[failed pending].include?(status) print_nonpassing_example(data) else print_passing_example end end |
#format_list_item(item) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spec_selector/format.rb', line 38 def format_list_item(item) description = lineage(item.) data = example?(item) ? [item] : fetch_examples(item) included = item.[:include] if @selected == item highlight(description, included: included) else green(description, included) if all_passed?(data) yellow(description, included) if any_pending?(data) && !any_failed?(data) red(description, included) if any_failed?(data) end end |
#highlight(text, included: false) ⇒ Object
64 65 66 67 |
# File 'lib/spec_selector/format.rb', line 64 def highlight(text, included: false) text += ' √' if included @output.puts "\e[1;7m#{text}\e[0m" end |
#lineage(data) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/spec_selector/format.rb', line 69 def lineage(data) parent = parent_data(data) return data[:description] unless parent "#{lineage(parent)} -> #{data[:description]}" end |
#pass_count ⇒ Object
52 53 54 |
# File 'lib/spec_selector/format.rb', line 52 def pass_count green("PASS: #{@pass_count}") end |
#pending_count ⇒ Object
56 57 58 |
# File 'lib/spec_selector/format.rb', line 56 def pending_count yellow("PENDING: #{@pending_count}") end |
#print_nonpassing_example(data) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/spec_selector/format.rb', line 84 def print_nonpassing_example(data) data = data.fully_formatted(@selector_index + 1).split("\n") data[0] = '' data.insert(1, '-' * term_width) data.insert(3, '-' * term_width) @output.puts data end |
#print_passing_example ⇒ Object
92 93 94 95 96 97 |
# File 'lib/spec_selector/format.rb', line 92 def print_passing_example @output.puts '-' * term_width @output.puts "#{@selector_index + 1}) " + @selected.description @output.puts '-' * term_width green('PASSED') end |