Class: Guard::Jstd::Formatter
- Inherits:
-
Object
- Object
- Guard::Jstd::Formatter
- Defined in:
- lib/guard/jstd/formatter.rb
Constant Summary collapse
- TITLES =
{ :failed => 'You have failing tests.', :success => "All of your tests passed.", :error => "You had some errors." }
- COLORS =
{ :success => "\e[32m", :failed => "\e[31m" }
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
Instance Method Summary collapse
- #any_failed? ⇒ Boolean
- #colorize_results ⇒ Object
- #errors_present? ⇒ Boolean
-
#initialize(results) ⇒ Formatter
constructor
A new instance of Formatter.
- #notify ⇒ Object
- #to_terminal ⇒ Object
Constructor Details
#initialize(results) ⇒ Formatter
Returns a new instance of Formatter.
25 26 27 28 |
# File 'lib/guard/jstd/formatter.rb', line 25 def initialize(results) @results = results @lines = results.split("\n") end |
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
23 24 25 |
# File 'lib/guard/jstd/formatter.rb', line 23 def lines @lines end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
23 24 25 |
# File 'lib/guard/jstd/formatter.rb', line 23 def results @results end |
Class Method Details
.notify(results) ⇒ Object
17 18 19 20 21 |
# File 'lib/guard/jstd/formatter.rb', line 17 def self.notify(results) formatter = self.new(results) formatter.notify formatter.to_terminal end |
Instance Method Details
#any_failed? ⇒ Boolean
30 31 32 |
# File 'lib/guard/jstd/formatter.rb', line 30 def any_failed? @failed ||= results.match(/failed/) end |
#colorize_results ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/guard/jstd/formatter.rb', line 54 def colorize_results lines.collect do |line| if line =~ /failed|error/ colorize(line, line, :failed) else if line =~ /((Passed: (\d+)); (Fails: (\d+)); (Errors:? (\d+)))/ if $5 == "0" && $7 == "0" colorize(line, line, :success) else # if $3 != "0" # colorize(line, $2, :success) # end [3, 5, 7].each do |tally| if eval("$#{tally}") != "0" status = tally == 3 ? :success : :failed colorize(line, eval("$#{tally - 1}"), status) end end end end line end end.join("\n") end |
#errors_present? ⇒ Boolean
34 35 36 |
# File 'lib/guard/jstd/formatter.rb', line 34 def errors_present? lines[0].match(/error/) end |
#notify ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/guard/jstd/formatter.rb', line 38 def notify if errors_present? status = :error image = { :image => :failed } = lines[0] else status = any_failed? ? :failed : :success image = { :image => status } = lines[1] end ::Guard::Notifier.notify( .lstrip, { :title => TITLES[status] }.merge(image) ) end |
#to_terminal ⇒ Object
80 81 82 |
# File 'lib/guard/jstd/formatter.rb', line 80 def to_terminal UI.info(colorize_results, :reset => true) end |