Module: Guard::PhantomJsJasmineCli
- Included in:
- PhantomJsJasmine, PhantomJsJasmineTask
- Defined in:
- lib/guard/phantomjs-jasmine/cli.rb
Overview
PhantomJS Jasmine command line utils
Instance Method Summary collapse
-
#error(msg) ⇒ Object
Helper to output error messages, colors in red.
-
#info(msg) ⇒ Object
Helper to output info messages.
-
#notify(msg, image) ⇒ Object
Helper to send notifications, not implemented We don’t use notify in CLI sessions.
-
#run(options) ⇒ Object
Command line runner Separated from guard so it’s possible to be used in rake tasks too.
Instance Method Details
#error(msg) ⇒ Object
Helper to output error messages, colors in red
61 62 63 |
# File 'lib/guard/phantomjs-jasmine/cli.rb', line 61 def error(msg) puts "\e[0;31m#{ msg }\e[0m" end |
#info(msg) ⇒ Object
Helper to output info messages
55 56 57 |
# File 'lib/guard/phantomjs-jasmine/cli.rb', line 55 def info(msg) puts msg end |
#notify(msg, image) ⇒ Object
Helper to send notifications, not implemented We don’t use notify in CLI sessions
69 70 |
# File 'lib/guard/phantomjs-jasmine/cli.rb', line 69 def notify(msg, image) end |
#run(options) ⇒ Object
Command line runner Separated from guard so it’s possible to be used in rake tasks too
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/guard/phantomjs-jasmine/cli.rb', line 12 def run() [:runner] ||= 'spec/runner.html' [:runner_script] ||= File.( 'js/jasmine_runner.coffee', File.dirname(__FILE__)) cmd = "phantomjs #{[:runner_script]} #{[:runner]}" result = IO.popen(cmd) begin parsed_result = JSON.parse(result.read, { :max_nesting => false, :symbolize_names => true }) result.close rescue Exception => exc error(exc.) return end passed = parsed_result[:passed] failed = parsed_result[:total] - passed run_time = (parsed_result[:ended] - parsed_result[:started]).round(3) parsed_result[:suites].each do |suite| msg = "\n" + "#{suite[:desc]} #{suite[:name]}\n\t#{suite[:spec]}".lstrip if suite[:passed] info( msg ) else error( "#{msg}\n\t\t#{suite[:trace]}" ) end end if failed > 0 notify("#{failed} Jasmine spec(s) failed.", :failed) info("\n#{failed}/#{parsed_result[:total]} failed in #{run_time} ms.") else notify("Jasmine specs passed.", :success) info("\n#{parsed_result[:total]} passed in #{run_time} ms.") end end |