Class: Qunit::Parser
- Inherits:
-
Object
- Object
- Qunit::Parser
- Defined in:
- lib/qunit/parser.rb
Instance Attribute Summary collapse
-
#current_module ⇒ Object
readonly
Returns the value of attribute current_module.
-
#current_test ⇒ Object
readonly
Returns the value of attribute current_test.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#failed_assertions ⇒ Object
readonly
Returns the value of attribute failed_assertions.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#total_failed ⇒ Object
readonly
Returns the value of attribute total_failed.
-
#total_passed ⇒ Object
readonly
Returns the value of attribute total_passed.
-
#unfinished_modules ⇒ Object
readonly
Returns the value of attribute unfinished_modules.
Instance Method Summary collapse
- #console(message) ⇒ Object
- #fail_load(url) ⇒ Object
- #fail_timeout ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #log_summary ⇒ Object
- #module_done(name, *args) ⇒ Object
- #module_start(name) ⇒ Object
- #parse(line) ⇒ Object
- #qunit_done(failed, passed, total, duration) ⇒ Object
- #qunit_log(result, actual, expected, message, source) ⇒ Object
- #test_done(name, failed, *args) ⇒ Object
- #test_start(name) ⇒ Object
Constructor Details
Instance Attribute Details
#current_module ⇒ Object (readonly)
Returns the value of attribute current_module.
6 7 8 |
# File 'lib/qunit/parser.rb', line 6 def current_module @current_module end |
#current_test ⇒ Object (readonly)
Returns the value of attribute current_test.
7 8 9 |
# File 'lib/qunit/parser.rb', line 7 def current_test @current_test end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
13 14 15 |
# File 'lib/qunit/parser.rb', line 13 def duration @duration end |
#failed_assertions ⇒ Object (readonly)
Returns the value of attribute failed_assertions.
9 10 11 |
# File 'lib/qunit/parser.rb', line 9 def failed_assertions @failed_assertions end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/qunit/parser.rb', line 14 def logger @logger end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
12 13 14 |
# File 'lib/qunit/parser.rb', line 12 def total @total end |
#total_failed ⇒ Object (readonly)
Returns the value of attribute total_failed.
10 11 12 |
# File 'lib/qunit/parser.rb', line 10 def total_failed @total_failed end |
#total_passed ⇒ Object (readonly)
Returns the value of attribute total_passed.
11 12 13 |
# File 'lib/qunit/parser.rb', line 11 def total_passed @total_passed end |
#unfinished_modules ⇒ Object (readonly)
Returns the value of attribute unfinished_modules.
8 9 10 |
# File 'lib/qunit/parser.rb', line 8 def unfinished_modules @unfinished_modules end |
Instance Method Details
#console(message) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/qunit/parser.rb', line 120 def console() prefix = '' if @current_test prefix << "\n[%s]" % @current_test elsif @current_module prefix << "\n[%s]" % @current_module end prefix << ' CONSOLE: ' logger.print prefix, :magenta logger.print logger.print "\n" end |
#fail_load(url) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/qunit/parser.rb', line 106 def fail_load(url) logger.puts "PhantomJS unable to load #{url} URI", :red @total_failed += 1 @total += 1 log_summary end |
#fail_timeout ⇒ Object
113 114 115 116 117 118 |
# File 'lib/qunit/parser.rb', line 113 def fail_timeout logger.puts "PhantomJS timed out.", :red @total_failed += 1 @total += 1 log_summary end |
#log_summary ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/qunit/parser.rb', line 133 def log_summary logger.puts '' @failed_assertions.each do |assertion| logger.puts assertion[:name] logger.puts "Message: #{assertion[:message]}", :red if assertion[:actual] != assertion[:expected] logger.puts "Actual: #{assertion[:actual]}", :magenta logger.puts "Expected: #{assertion[:expected]}", :yellow end if assertion[:source] logger.puts assertion[:source], :cyan end logger.puts '' end if @total == 0 logger.puts "0/0 assertions ran (#{@duration/1000.0}s)", :magenta else logger.puts "#{@total_passed}/#{@total} assertions passed (#{@duration/1000.0}s)" end if @total_failed == 0 and @total > 0 logger.puts "OK", :green # exit status return true, 0 else # exit status return true, 1 end end |
#module_done(name, *args) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/qunit/parser.rb', line 59 def module_done(name, *args) name ||= "Unnamed Module" @unfinished_modules.delete(name.to_sym) # exit status return false, nil end |
#module_start(name) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/qunit/parser.rb', line 51 def module_start(name) name ||= "Unnamed Module" @unfinished_modules[name.to_sym] = true @current_module = name # exit status return false, nil end |
#parse(line) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/qunit/parser.rb', line 26 def parse(line) params = JSON.parse line event = params.shift case event when 'qunit.moduleStart' module_start *params when 'qunit.moduleDone' module_done *params when 'qunit.testStart' test_start *params when 'qunit.testDone' test_done *params when 'qunit.log' qunit_log *params when 'qunit.done' qunit_done *params when 'fail.load' fail_load *params when 'fail.timeout' fail_timeout *params when 'console' console *params end end |
#qunit_done(failed, passed, total, duration) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/qunit/parser.rb', line 98 def qunit_done(failed, passed, total, duration) @total_failed += failed @total_passed += passed @total += total @duration += duration log_summary end |
#qunit_log(result, actual, expected, message, source) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/qunit/parser.rb', line 83 def qunit_log(result, actual, expected, , source) if not result assertion = { name: @current_test, actual: actual, expected: expected, message: , source: source } @failed_assertions.push assertion end # exit status return false, nil end |
#test_done(name, failed, *args) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/qunit/parser.rb', line 73 def test_done(name, failed, *args) if failed > 0 logger.print 'F', :red else logger.print '.' end # exit status return false, nil end |
#test_start(name) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/qunit/parser.rb', line 66 def test_start(name) prefix = @current_module ? "#{@current_module} - " : '' @current_test = "#{prefix}#{name}" # exit status return false, nil end |