Class: RspecSpinner::RspecSpinnerBase
- Inherits:
-
Spec::Runner::Formatter::BaseTextFormatter
- Object
- Spec::Runner::Formatter::BaseTextFormatter
- RspecSpinner::RspecSpinnerBase
show all
- Defined in:
- lib/rspec_spinner/base.rb
Constant Summary
collapse
- THRESHOLD =
Threshold for slow specs, in seconds. Anything that takes longer than this will be printed out THRESHOLD = 0.25
3.0
- ERROR_STATE_COLORS =
{
:all_passing => "\e[32m", :some_pending => "\e[33m", :some_failed => "\e[31m", :pending_fix => "\e[34m", }
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#dump_failure(*args) ⇒ Object
-
#erase_current_line ⇒ Object
-
#example_failed(example, counter, failure) ⇒ Object
-
#example_passed(example) ⇒ Object
-
#example_pending(example, message, pending_caller = nil) ⇒ Object
third param is optional, because earlier versions of rspec sent only two args.
-
#example_started(example) ⇒ Object
-
#immediately_dump_failure(counter, failure) ⇒ Object
stolen and slightly modified from BaseTextFormatter#dump_failure.
-
#immediately_dump_pending(desc, msg, called_from) ⇒ Object
stolen and modified from BaseTextFormatter#dump_pending.
-
#increment ⇒ Object
-
#mark_error_state_failed ⇒ Object
-
#mark_error_state_pending ⇒ Object
-
#method_missing(sym, *args) ⇒ Object
-
#print_warning_if_slow(group, example, elapsed) ⇒ Object
-
#start(example_count) ⇒ Object
-
#start_dump ⇒ Object
-
#with_color ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
56
57
58
|
# File 'lib/rspec_spinner/base.rb', line 56
def method_missing(sym, *args)
end
|
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
12
13
14
|
# File 'lib/rspec_spinner/base.rb', line 12
def current
@current
end
|
#total ⇒ Object
Returns the value of attribute total.
12
13
14
|
# File 'lib/rspec_spinner/base.rb', line 12
def total
@total
end
|
Instance Method Details
#dump_failure(*args) ⇒ Object
52
53
54
|
# File 'lib/rspec_spinner/base.rb', line 52
def dump_failure(*args)
end
|
#erase_current_line ⇒ Object
111
112
113
|
# File 'lib/rspec_spinner/base.rb', line 111
def erase_current_line
output.print "\e[K"
end
|
#example_failed(example, counter, failure) ⇒ Object
42
43
44
45
46
|
# File 'lib/rspec_spinner/base.rb', line 42
def example_failed(example, counter, failure)
immediately_dump_failure(counter, failure)
mark_error_state_failed
increment
end
|
#example_passed(example) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/rspec_spinner/base.rb', line 27
def example_passed(example)
print_warning_if_slow(example_group.description,
example.description,
Time.now - @start_time)
increment
end
|
#example_pending(example, message, pending_caller = nil) ⇒ Object
third param is optional, because earlier versions of rspec sent only two args
35
36
37
38
39
40
|
# File 'lib/rspec_spinner/base.rb', line 35
def example_pending(example, message, pending_caller=nil)
desc = example.respond_to?(:full_description) ? example.full_description : example.description
immediately_dump_pending(desc, message, pending_caller)
mark_error_state_pending
increment
end
|
#example_started(example) ⇒ Object
22
23
24
25
|
# File 'lib/rspec_spinner/base.rb', line 22
def example_started(example)
super
@start_time = Time.now
end
|
stolen and slightly modified from BaseTextFormatter#dump_failure
61
62
63
64
65
66
67
68
|
# File 'lib/rspec_spinner/base.rb', line 61
def immediately_dump_failure(counter, failure)
erase_current_line
output.puts
output.print "#{counter.to_s}) "
output.puts colourise("#{failure.}\n#{failure.exception.message}", failure)
output.puts format_backtrace(failure.exception.backtrace)
output.puts
end
|
stolen and modified from BaseTextFormatter#dump_pending
71
72
73
74
75
76
|
# File 'lib/rspec_spinner/base.rb', line 71
def immediately_dump_pending(desc, msg, called_from)
erase_current_line
output.puts yellow("PENDING SPEC:") + " #{desc} (#{msg})"
output.puts format_backtrace(" Called from #{called_from}") if called_from
output.puts
end
|
#increment ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rspec_spinner/base.rb', line 78
def increment
with_color do
@current += 1
@pbar.instance_variable_set("@previous", 0)
@pbar.instance_variable_set("@title", "#{current}/#{total}")
@pbar.inc
end
output.flush
end
|
#mark_error_state_failed ⇒ Object
103
104
105
|
# File 'lib/rspec_spinner/base.rb', line 103
def mark_error_state_failed
@error_state = :some_failed
end
|
#mark_error_state_pending ⇒ Object
107
108
109
|
# File 'lib/rspec_spinner/base.rb', line 107
def mark_error_state_pending
@error_state = :some_pending unless @error_state == :some_failed
end
|
#print_warning_if_slow(group, example, elapsed) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/rspec_spinner/base.rb', line 115
def print_warning_if_slow(group, example, elapsed)
if elapsed > THRESHOLD
erase_current_line
output.print yellow("SLOW SPEC: #{sprintf("%.4f", elapsed)} ")
output.print " #{group} #{example}"
output.puts
end
end
|
#start(example_count) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/rspec_spinner/base.rb', line 14
def start(example_count)
@current = 0
@total = example_count
@error_state = :all_passing
@pbar = Rtui::Progress.new("#{example_count} examples", example_count,
{:out => output, :components => [:percentage, :spinner, :stat]})
end
|
#start_dump ⇒ Object
48
49
50
|
# File 'lib/rspec_spinner/base.rb', line 48
def start_dump
output.flush
end
|
#with_color ⇒ Object
96
97
98
99
100
101
|
# File 'lib/rspec_spinner/base.rb', line 96
def with_color
use_color = colour? && output_to_tty?
output.print ERROR_STATE_COLORS[@error_state] if use_color
yield
output.print "\e[0m" if use_color
end
|