Sha256: 18fd49223f624862b933d3b61604c5d02571c52af403231680c96f61dbd690db

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'guard/notifier'

module Guard
  class JasmineHeadlessWebkitRunner
    class << self
      def run(paths = [])
        lines = [""]

        Open3.popen3(%{jasmine-headless-webkit -c #{paths.join(" ")}}) do |stdin, stdout, stderr|
          stdin.close
          stderr.close
          while !stdout.eof?
            $stdout.print (char = stdout.getc)
            $stdout.flush

            if char.chr == "\n"
              lines << ""
            else
              lines.last << char.chr
            end
          end
        end

        total, fails, secs = lines[-2].scan(%r{.* (\d+) tests, (\d+) failures, (.+) secs..*}).flatten

        any_console = lines.any? { |line| line['[console] '] }

        Notifier.notify(message(total, fails, secs, any_console), :title => 'Jasmine results', :image => image(any_console, fails))
        fails.to_i
      end

      private
      def message(total, fails, secs, any_console)
        "#{total} tests, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
      end

      def image(any_console, fails)
        if any_console
          :pending
        else
          if fails.to_i == 0
            :success
          else
            :failed
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
guard-jasmine-headless-webkit-0.0.2 lib/guard/jasmine-headless-webkit/runner.rb