guard-konacha 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # Guard::Bundler
1
+ # Guard::Konacha
2
2
 
3
3
  Automatically run your [Konacha](https://github.com/jfirebaugh/konacha) tests through [Guard](https://github.com/guard/guard/).
4
4
 
@@ -30,4 +30,8 @@ If your specs live outside of `spec/javascripts` then tell Konacha where to find
30
30
 
31
31
  ## Development
32
32
 
33
- This is a work in progress and could use some help.
33
+ This is a work in progress and could use some help.
34
+
35
+ ## Contributors
36
+
37
+ [https://github.com/guard/guard/contributors](https://github.com/alexgb/guard-konacha/graphs/contributors)
data/lib/guard/konacha.rb CHANGED
@@ -4,38 +4,37 @@ require 'guard/guard'
4
4
  module Guard
5
5
  class Konacha < Guard
6
6
 
7
+ autoload :Runner, 'guard/konacha/runner'
8
+ attr_accessor :runner
9
+
7
10
  def initialize(watchers=[], options={})
8
11
  super
9
- @spec_dir = options[:spec_dir] || 'spec/javascripts'
12
+ @runner = Runner.new(options)
10
13
  end
11
14
 
12
15
  def start
13
- run_all
16
+ runner.kill_konacha
17
+ runner.launch_konacha("Start")
18
+ end
19
+
20
+ def reload
21
+ runner.kill_konacha
22
+ runner.launch_konacha("Reload")
14
23
  end
15
24
 
16
25
  def run_all
17
- run_konacha
26
+ runner.run_all
18
27
  end
19
28
 
20
29
  def run_on_changes(paths)
21
- run_konacha(paths)
30
+ runner.run(paths)
22
31
  end
32
+ # for guard 1.0.x and earlier
33
+ alias :run_on_change :run_on_changes
23
34
 
24
- def run_konacha(paths=[])
25
- files = paths.map { |p| p.to_s.sub(%r{^#{@spec_dir}/}, '').sub(/(.js\.coffee|\.js|\.coffee)/, '') }
26
- option = files.empty? ? '' : "SPEC=#{files.join(',')}"
27
- cmd = "bundle exec rake konacha:run #{option}"
28
-
29
- ::Guard::UI.info "Konacha: #{cmd}"
30
- result = `bundle exec rake konacha:run #{option}`
31
-
32
- last_line = result.split("\n").last
33
- examples, failures = last_line.scan(/\d/).map { |s| s.to_i }
34
- image = failures > 0 ? :failed : :success
35
-
36
- ::Guard::UI.info result
37
- ::Guard::Notifier.notify(last_line, :title => 'Konacha Specs', :image => image )
35
+ def stop
36
+ runner.kill_konacha
38
37
  end
39
38
 
40
39
  end
41
- end
40
+ end
@@ -0,0 +1,92 @@
1
+ module Guard
2
+ class Konacha
3
+ class Runner
4
+
5
+ DEFAULT_OPTIONS = {
6
+ :bundler => true,
7
+ :spec_dir => 'spec/javascripts',
8
+ :run_all => true,
9
+ :notification => true
10
+ }
11
+
12
+ attr_reader :options
13
+
14
+ def initialize(options={})
15
+ @options = DEFAULT_OPTIONS.merge(options)
16
+ UI.info "Guard::Konacha Initialized"
17
+ end
18
+
19
+ def launch_konacha(action)
20
+ UI.info "#{action}ing Konacha", :reset => true
21
+ spawn_konacha(spawn_konacha_command)
22
+ end
23
+
24
+ def kill_konacha
25
+ return unless @konacha_pid
26
+
27
+ Process.kill(:INT, @konacha_pid)
28
+
29
+ begin
30
+ unless Process.waitpid(@konacha_pid, Process::WNOHANG)
31
+ Process.kill(:KILL, @konacha_pid)
32
+ end
33
+ rescue Errno::ECHILD
34
+ end
35
+ UI.info "Konacha Stopped", :reset => true
36
+ end
37
+
38
+ def run(paths=[])
39
+ UI.info "Konacha Running: #{paths.join(' ')}"
40
+ result = run_command(konacha_command(paths))
41
+ UI.info "Konacha Results: #{result}"
42
+
43
+ if @options[:notification]
44
+ last_line = result.split("\n").last
45
+ examples, failures = last_line.scan(/\d/).map { |s| s.to_i }
46
+ image = failures > 0 ? :failed : :success
47
+ ::Guard::Notifier.notify(last_line, :title => 'Konacha Specs', :image => image )
48
+ end
49
+ end
50
+
51
+ def run_all
52
+ return unless @options[:run_all]
53
+ run
54
+ end
55
+
56
+ private
57
+
58
+ def run_command(command)
59
+ `#{command}`
60
+ end
61
+
62
+ def spawn_konacha_command
63
+ cmd_parts = []
64
+ cmd_parts << "bundle exec" if bundler?
65
+ cmd_parts << "rake konacha:serve"
66
+ cmd_parts.join(' ')
67
+ end
68
+
69
+ def konacha_command(paths)
70
+ files = []
71
+ files = paths.map { |p| p.to_s.sub(%r{^#{@options[:spec_dir]}/}, '').sub(/(.js\.coffee|\.js|\.coffee)/, '') }
72
+ option = files.empty? ? '' : "SPEC=#{files.join(',')}"
73
+
74
+ cmd_parts = []
75
+ cmd_parts << "bundle exec" if bundler?
76
+ cmd_parts << "rake konacha:run"
77
+ cmd_parts << option
78
+ cmd_parts.join(' ').strip
79
+ end
80
+
81
+ def spawn_konacha(cmd)
82
+ @konacha_pid = fork do
83
+ exec "#{spawn_konacha_command}"
84
+ end
85
+ end
86
+
87
+ def bundler?
88
+ @bundler ||= options[:bundler] != false && File.exist?("#{Dir.pwd}/Gemfile")
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,7 @@
1
+ ### Guard::Konacha
2
+ # available options:
3
+ # - :spec_dir
4
+ guard :konacha do
5
+ watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" }
6
+ watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)})
7
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module KonachaVersion
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-konacha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-15 00:00:00.000000000 Z
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -43,6 +43,38 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '1.4'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
46
78
  description: Automatically run konacha tests
47
79
  email:
48
80
  - alex.gibbons@gmail.com
@@ -50,6 +82,9 @@ executables: []
50
82
  extensions: []
51
83
  extra_rdoc_files: []
52
84
  files:
85
+ - lib/guard/konacha/runner.rb
86
+ - lib/guard/konacha/templates/Guardfile
87
+ - lib/guard/konacha/version.rb
53
88
  - lib/guard/konacha.rb
54
89
  - LICENSE
55
90
  - Readme.md