guard-karma 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 341a5d5b1978a0333bb65d6465f84d6187729246
4
- data.tar.gz: f377973ca24552c9230712047bcf00e0da1bf25c
3
+ metadata.gz: 043476f09a4cc1a31c34230ed15b82988012b6f2
4
+ data.tar.gz: 2f9be928d2cdde3b85dc8135d586c5a1eb871f29
5
5
  SHA512:
6
- metadata.gz: f9401c431108ec033d453c8735d941131de9f262c3ecd970c7013905b0631a8235f66b9c6c8384c07b785e9ca0ab1c7a9fa858cc0a2a221a0b8bd3a43b8abe2a
7
- data.tar.gz: 7e899ce1dcb8ee1639b05aefc88b99a570008e4545e5459c7a58576609f9eb5ccee26b4c5b4d8f468eccfabcb5b373b490a7b08c0b84c046e3c26ceb121893ae
6
+ metadata.gz: d40aefde9749be45c93ef688c35ee3e050443299057c24f9bc58b42098e095c862fdc8ba7dd84adc83721f7f9261849e77c40cb053f72b2b0fc02498e96c6aca
7
+ data.tar.gz: f6c7736a573d6a607ce099e4c9a4e5db8ebea9090030bf53fcc5cc4dcc8617687a1aa7a34094af31a72e26bce02b29bc2df4b529a0280917631e08d31071fa22
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Guard::Karma
2
2
 
3
3
  Guard plugin for [Karma](http://karma-runner.github.io/0.12/index.html).
4
- Unfortunatelly I couldn't find a way to run specific test file, so it runs them all, but it's still useful for me.
4
+ Unfortunately I couldn't find a way to run specific test file, so it runs them all, but it's still useful for me.
5
5
 
6
6
  ## Installation
7
7
 
@@ -37,6 +37,7 @@ Supported options:
37
37
  ./node_modules/karma/bin/karma start spec/karma.conf.coffee --single-run
38
38
  ```
39
39
  - `all_on_start` - when true, tests will be run on guard start
40
+ - `notification` - when true, display notification before and after tests run
40
41
 
41
42
 
42
43
  ## Contributing
data/lib/guard/karma.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "guard/karma/version"
2
+ require "guard/karma/notifier"
2
3
 
3
4
  module Guard
4
5
  class Karma < Guard::Plugin
@@ -9,9 +10,11 @@ module Guard
9
10
  # @option options [Array<Guard::Watcher>] watchers the Guard plugin file watchers
10
11
  # @option options [Symbol] group the group this Guard plugin belongs to
11
12
  # @option options [Boolean] any_return allow any object to be returned from a watcher
13
+ # @option options [Boolean] notification display notifications when tests run
12
14
  #
13
15
  def initialize(options = {})
14
16
  super
17
+ @notifier = Notifier.new(options)
15
18
  end
16
19
 
17
20
  # Called once when Guard starts. Please override initialize method to init stuff.
@@ -83,7 +86,13 @@ module Guard
83
86
  private
84
87
 
85
88
  def run_cmd
86
- system(options[:cmd])
89
+ Guard::Compat::UI.info('Running Karma', reset: true)
90
+
91
+ @notifier.notify_start
92
+
93
+ output = IO.popen(options[:cmd]) { |f| f.readlines.tap { |out| puts out } }
94
+
95
+ @notifier.notify(output.last)
87
96
  end
88
97
  end
89
98
  end
@@ -0,0 +1,71 @@
1
+ module Guard
2
+ class Karma < Guard::Plugin
3
+ class Notifier
4
+ RUNNING_TITLE = 'Karma running...'.freeze
5
+ FAILURE_TITLE = 'Karma failure.'.freeze
6
+ SUCCESS_TITLE = 'Karma success.'.freeze
7
+
8
+ attr_accessor :options
9
+
10
+ def initialize(options = {})
11
+ @options = options
12
+ end
13
+
14
+ def notify_start
15
+ return unless options[:notification]
16
+
17
+ Guard::Compat::UI.notify('', title: RUNNING_TITLE, image: :pending, priority: -1)
18
+ end
19
+
20
+ def notify(summary)
21
+ return unless options[:notification]
22
+
23
+ run_count, total_count, failure_count = parse_summary(summary)
24
+
25
+ body = "Executed #{run_count} of #{total_count}"
26
+ if failure_count > 0
27
+ body += " with #{failure_count} failure(s)"
28
+ end
29
+
30
+ title = title(failure_count)
31
+ image = image(failure_count)
32
+ priority = priority(image)
33
+ Guard::Compat::UI.notify(body, title: title, image: image, priority: priority)
34
+ end
35
+
36
+ private
37
+
38
+ def parse_summary(summary)
39
+ summary.match(/Executed\ (\d+)\ of\ (\d+)\ \((\d+)\ FAILED\)/) do |match|
40
+ return [match[1].to_i, match[2].to_i, match[3].to_i]
41
+ end
42
+
43
+ summary.match(/Executed\ (\d+)\ of\ (\d+)\ SUCCESS/) do |match|
44
+ return [match[1].to_i, match[2].to_i, 0]
45
+ end
46
+
47
+ [0, 0, 0]
48
+ end
49
+
50
+ def image(failure_count)
51
+ if failure_count > 0
52
+ :failed
53
+ else
54
+ :success
55
+ end
56
+ end
57
+
58
+ def priority(image)
59
+ { failed: 2, success: -1 }[image]
60
+ end
61
+
62
+ def title(failure_count)
63
+ if failure_count > 0
64
+ FAILURE_TITLE
65
+ else
66
+ SUCCESS_TITLE
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module KarmaVersion
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-karma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ania Slimak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - Rakefile
81
81
  - guard-karma.gemspec
82
82
  - lib/guard/karma.rb
83
+ - lib/guard/karma/notifier.rb
83
84
  - lib/guard/karma/templates/Guardfile
84
85
  - lib/guard/karma/version.rb
85
86
  homepage: https://github.com/lesniakania/guard-karma
@@ -102,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  requirements: []
104
105
  rubyforge_project:
105
- rubygems_version: 2.2.2
106
+ rubygems_version: 2.4.8
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: Guard plugin for Karma runner
109
110
  test_files: []
110
- has_rdoc: