Class: RspecSpinner::RspecSpinnerBase
- Inherits:
-
RSpec::Core::Formatters::BaseTextFormatter
- Object
- RSpec::Core::Formatters::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
Class Method 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, deprecated_pending_location = 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, location) ⇒ Object
stolen and modified from BaseTextFormatter#dump_pending.
-
#increment ⇒ Object
-
#initialize(options, where = nil) ⇒ RspecSpinnerBase
constructor
A new instance of RspecSpinnerBase.
-
#mark_error_state_failed ⇒ Object
-
#mark_error_state_pending ⇒ Object
-
#method_missing(sym, *args) ⇒ Object
-
#print_warning_if_slow(group, example, location, elapsed) ⇒ Object
-
#start(example_count) ⇒ Object
-
#start_dump ⇒ Object
-
#with_color ⇒ Object
Constructor Details
#initialize(options, where = nil) ⇒ RspecSpinnerBase
Returns a new instance of RspecSpinnerBase.
20
21
22
23
|
# File 'lib/rspec_spinner/base.rb', line 20
def initialize(options, where=nil)
super options
@example_times = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
79
80
81
|
# File 'lib/rspec_spinner/base.rb', line 79
def method_missing(sym, *args)
end
|
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
18
19
20
|
# File 'lib/rspec_spinner/base.rb', line 18
def current
@current
end
|
#total ⇒ Object
Returns the value of attribute total.
18
19
20
|
# File 'lib/rspec_spinner/base.rb', line 18
def total
@total
end
|
Class Method Details
.fmt_backtrace(bkt) ⇒ Object
83
84
85
86
|
# File 'lib/rspec_spinner/base.rb', line 83
def self.fmt_backtrace(bkt)
return "" if bkt.nil?
return bkt.split("\n")
end
|
Instance Method Details
#dump_failure(*args) ⇒ Object
75
76
77
|
# File 'lib/rspec_spinner/base.rb', line 75
def dump_failure(*args)
end
|
#erase_current_line ⇒ Object
146
147
148
|
# File 'lib/rspec_spinner/base.rb', line 146
def erase_current_line
output.print "\e[K"
end
|
#example_failed(example, counter, failure) ⇒ Object
52
53
54
55
56
|
# File 'lib/rspec_spinner/base.rb', line 52
def example_failed(example, counter, failure)
immediately_dump_failure(counter, failure)
mark_error_state_failed
increment
end
|
#example_passed(example) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/rspec_spinner/base.rb', line 38
def example_passed(example)
ex = [example_group.description, example.description, example.location, Time.now - @start_time]
print_warning_if_slow(*ex)
@example_times << ex
increment
end
|
#example_pending(example, message, deprecated_pending_location = nil) ⇒ Object
third param is optional, because earlier versions of rspec sent only two args
46
47
48
49
50
|
# File 'lib/rspec_spinner/base.rb', line 46
def example_pending(example, message, deprecated_pending_location=nil)
immediately_dump_pending(example.description, message, example.location)
mark_error_state_pending
increment
end
|
#example_started(example) ⇒ Object
33
34
35
36
|
# File 'lib/rspec_spinner/base.rb', line 33
def example_started(example)
super
@start_time = Time.now
end
|
stolen and slightly modified from BaseTextFormatter#dump_failure
89
90
91
92
93
94
95
96
97
|
# File 'lib/rspec_spinner/base.rb', line 89
def immediately_dump_failure(counter, failure)
erase_current_line
output.puts
output.print "#{counter.to_s}) "
output.puts colorize_failure("#{failure.}\n#{failure.exception.message}", failure)
output.puts failure.exception.backtrace
output.puts
end
|
stolen and modified from BaseTextFormatter#dump_pending
101
102
103
104
105
106
|
# File 'lib/rspec_spinner/base.rb', line 101
def immediately_dump_pending(desc, msg, location)
erase_current_line
output.puts yellow("PENDING SPEC:") + " #{desc} (#{msg})"
output.puts " Called from #{location}"
output.puts
end
|
#increment ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/rspec_spinner/base.rb', line 108
def increment
with_color do
@current += 1
if /^1\.8/ === RUBY_VERSION then
@pbar.instance_variable_set("@previous", 0)
@pbar.instance_variable_set("@title", "#{current}/#{total}")
else
@pbar.instance_variable_set("@previous".to_sym, 0)
@pbar.instance_variable_set("@title".to_sym, "#{current}/#{total}")
end
@pbar.inc
end
output.flush
end
|
#mark_error_state_failed ⇒ Object
138
139
140
|
# File 'lib/rspec_spinner/base.rb', line 138
def mark_error_state_failed
@error_state = :some_failed
end
|
#mark_error_state_pending ⇒ Object
142
143
144
|
# File 'lib/rspec_spinner/base.rb', line 142
def mark_error_state_pending
@error_state = :some_pending unless @error_state == :some_failed
end
|
#print_warning_if_slow(group, example, location, elapsed) ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/rspec_spinner/base.rb', line 150
def print_warning_if_slow(group, example, location, elapsed)
if elapsed > THRESHOLD
erase_current_line
output.print yellow("SLOW SPEC: #{sprintf("%.4f", elapsed)} ")
output.print " FROM: #{location} / #{group} #{example}"
output.puts
end
end
|
#start(example_count) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/rspec_spinner/base.rb', line 25
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/rspec_spinner/base.rb', line 58
def start_dump
output.flush
super
@output.puts "\n\nTop 15 slowest examples:\n"
@example_times = @example_times.sort_by do |description, example, location, time|
time
end.reverse
@example_times[0..14].each do |description, example, location, time|
_, line = location.split(":")
@output.print red(sprintf("%.7f", time))
@output.puts " #{description}:#{line} #{example}"
end
@output.flush
end
|
#with_color ⇒ Object
131
132
133
134
135
136
|
# File 'lib/rspec_spinner/base.rb', line 131
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
|