Class: RspecTickFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseTextFormatter
- Object
- RSpec::Core::Formatters::BaseTextFormatter
- RspecTickFormatter
- Defined in:
- lib/rspec-tick-formatter/formatter.rb
Constant Summary collapse
- VT100_CODES =
Shamelessly “Borrowed” from the excellent nyan cat formatter Source: github.com/mattsears/nyan-cat-formatter/blob/master/lib/nyan_cat_formatter/common.rb
{ :black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 37, :bold => 1, }
- VT100_CODE_VALUES =
VT100_CODES.invert
Instance Method Summary collapse
- #color(text, code_or_symbol) ⇒ Object
- #console_code_for(code_or_symbol) ⇒ Object
- #example_failed(proxy) ⇒ Object
- #example_group_finished(example_group) ⇒ Object
- #example_group_started(example_group) ⇒ Object
- #example_passed(proxy) ⇒ Object
- #example_pending(proxy) ⇒ Object
-
#initialize(output) ⇒ RspecTickFormatter
constructor
A new instance of RspecTickFormatter.
- #pad ⇒ Object
Constructor Details
#initialize(output) ⇒ RspecTickFormatter
Returns a new instance of RspecTickFormatter.
4 5 6 7 8 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 4 def initialize(output) super(output) @level = 0 end |
Instance Method Details
#color(text, code_or_symbol) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 38 def color(text, code_or_symbol) if RSpec.configuration.color_enabled? "\e[#{console_code_for(code_or_symbol)}m#{text}\e[0m" else text end end |
#console_code_for(code_or_symbol) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 62 def console_code_for(code_or_symbol) if VT100_CODE_VALUES.has_key?(code_or_symbol) code_or_symbol else VT100_CODES.fetch(code_or_symbol) do console_code_for(:white) end end end |
#example_failed(proxy) ⇒ Object
21 22 23 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 21 def example_failed(proxy) puts color("#{pad} \u2717 #{proxy.example.description}: #{proxy.example.exception}", :red) end |
#example_group_finished(example_group) ⇒ Object
30 31 32 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 30 def example_group_finished(example_group) @level -= 1 end |
#example_group_started(example_group) ⇒ Object
25 26 27 28 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 25 def example_group_started(example_group) puts "#{pad} #{example_group.group.description.strip}:" @level += 1 end |
#example_passed(proxy) ⇒ Object
13 14 15 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 13 def example_passed(proxy) puts color("#{pad} \u2713 #{proxy.example.description}", :green) end |
#example_pending(proxy) ⇒ Object
17 18 19 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 17 def example_pending(proxy) puts color("#{pad} \u2729 #{proxy.example.description}", :yellow) end |
#pad ⇒ Object
34 35 36 |
# File 'lib/rspec-tick-formatter/formatter.rb', line 34 def pad ' ' * @level * 2 end |