guard-konacha 0.1.4 → 0.2.0

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
@@ -27,11 +27,23 @@ If your specs live outside of `spec/javascripts` then tell Konacha where to find
27
27
  guard :konacha, :spec_dir => 'spec/front-end' do
28
28
  # ...
29
29
  end
30
-
30
+
31
+ If you want to use capybara-webkit instead of the default selenium
32
+ driver:
33
+
34
+ require 'capybara-webkit'
35
+
36
+ guard :konacha, :driver => :webkit do
37
+ # ...
38
+ end
39
+
40
+ If you are running konacha:serve on a different host or port than the
41
+ default `localhost` and `3500`, the configuration settings `:host` and `:port` will help you there.
42
+
31
43
  ## Development
32
44
 
33
45
  This is a work in progress and could use some help.
34
46
 
35
47
  ## Contributors
36
48
 
37
- [https://github.com/alexgb/guard-konacha/graphs/contributors](https://github.com/alexgb/guard-konacha/graphs/contributors)
49
+ [https://github.com/alexgb/guard-konacha/graphs/contributors](https://github.com/alexgb/guard-konacha/graphs/contributors)
@@ -1,4 +1,11 @@
1
+ require 'net/http'
1
2
  require 'childprocess'
3
+ require 'capybara'
4
+ require 'active_support/core_ext/module/delegation'
5
+ require 'active_support/core_ext/object/blank'
6
+ require 'konacha/reporter'
7
+ require 'konacha/formatter'
8
+ require 'konacha/runner'
2
9
 
3
10
  module Guard
4
11
  class Konacha
@@ -8,6 +15,9 @@ module Guard
8
15
  :bundler => true,
9
16
  :spec_dir => 'spec/javascripts',
10
17
  :run_all => true,
18
+ :driver => :selenium,
19
+ :host => 'localhost',
20
+ :port => 3500,
11
21
  :notification => true
12
22
  }
13
23
 
@@ -25,23 +35,62 @@ module Guard
25
35
 
26
36
  def kill_konacha
27
37
  if @process
28
- @process.stop(5)
38
+ @process.stop(5)
29
39
  UI.info "Konacha Stopped", :reset => true
30
40
  end
31
41
  end
32
42
 
33
43
  def run(paths=[])
34
- UI.info "Konacha Running: #{paths.join(' ')}"
35
- result = run_command(konacha_command(paths))
44
+ return UI.info("Konacha server not running") unless konacha_running?
45
+
46
+ UI.info "Konacha Running: #{paths.empty? ? 'All tests' : paths.join(' ')}"
47
+
48
+ urls = paths.map { |p| konacha_url(p) }
49
+ urls = [konacha_url] if paths.empty?
50
+
51
+ test_results = {
52
+ :examples => 0,
53
+ :failures => 0,
54
+ :pending => 0,
55
+ :duration => 0
56
+ }
57
+
58
+ urls.each do |url|
59
+ individual_result = run_tests(url)
60
+
61
+ test_results[:examples] += individual_result[:examples]
62
+ test_results[:failures] += individual_result[:failures]
63
+ test_results[:pending] += individual_result[:pending]
64
+ test_results[:duration] += individual_result[:duration]
65
+ end
66
+
67
+
68
+ result_line = "#{test_results[:examples]} examples, #{test_results[:failures]} failures"
69
+ result_line << ", #{test_results[:pending]} pending" if test_results[:pending] > 0
70
+ text = [
71
+ result_line,
72
+ "in #{"%.2f" % test_results[:duration]} seconds"
73
+ ].join "\n"
74
+
75
+ UI.info text if urls.length > 1
36
76
 
37
77
  if @options[:notification]
38
- last_line = result.split("\n").last
39
- examples, failures = last_line.scan(/\d+/).map { |s| s.to_i }
40
- image = failures > 0 ? :failed : :success
41
- ::Guard::Notifier.notify(last_line, :title => 'Konacha Specs', :image => image )
78
+ image = test_results[:failures] > 0 ? :failed : :success
79
+ ::Guard::Notifier.notify(text, :title => 'Konacha Specs', :image => image )
42
80
  end
43
81
  end
44
82
 
83
+ def run_tests(url)
84
+ runner = ::Konacha::Runner.new session
85
+ runner.run url
86
+ return {
87
+ :examples => runner.reporter.example_count,
88
+ :failures => runner.reporter.failure_count,
89
+ :pending => runner.reporter.pending_count,
90
+ :duration => runner.reporter.duration
91
+ }
92
+ end
93
+
45
94
  def run_all
46
95
  return unless @options[:run_all]
47
96
  run
@@ -49,9 +98,16 @@ module Guard
49
98
 
50
99
  private
51
100
 
52
- def run_command(cmd)
53
- puts result = `#{cmd}`
54
- result
101
+ def konacha_url(path = nil)
102
+ url_path = path.gsub(/^#{@options[:spec_dir]}\/?/, '').gsub(/\.coffee$/, '').gsub(/\.js$/, '') unless path.nil?
103
+ "#{konacha_base_url}/#{url_path}?mode=runner"
104
+ end
105
+
106
+ def session
107
+ UI.info "Starting Konacha-Capybara session using #{@options[:driver]} driver, this can take a few seconds..." if @session.nil?
108
+ @session ||= Capybara::Session.new @options[:driver]
109
+ # @session.reset!
110
+ # @session
55
111
  end
56
112
 
57
113
  def spawn_konacha_command
@@ -61,22 +117,21 @@ module Guard
61
117
  cmd_parts.join(' ')
62
118
  end
63
119
 
64
- def konacha_command(paths)
65
- files = []
66
- files = paths.map { |p| p.to_s.sub(%r{^#{@options[:spec_dir]}/}, '').sub(/(.js\.coffee|\.js|\.coffee)/, '') }
67
- option = files.empty? ? '' : "SPEC=#{files.join(',')}"
120
+ def spawn_konacha
121
+ unless @process
122
+ @process = ChildProcess.build(spawn_konacha_command)
123
+ @process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
124
+ @process.start
125
+ end
126
+ end
68
127
 
69
- cmd_parts = []
70
- cmd_parts << "bundle exec" if bundler?
71
- cmd_parts << "rake konacha:run"
72
- cmd_parts << option
73
- cmd_parts.join(' ').strip
128
+ def konacha_base_url
129
+ "http://#{@options[:host]}:#{@options[:port]}"
74
130
  end
75
131
 
76
- def spawn_konacha
77
- @process = ChildProcess.build(spawn_konacha_command)
78
- @process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
79
- @process.start
132
+ def konacha_running?
133
+ Net::HTTP.get_response(URI.parse(konacha_base_url))
134
+ rescue Errno::ECONNREFUSED
80
135
  end
81
136
 
82
137
  def bundler?
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module KonachaVersion
3
- VERSION = "0.1.4"
3
+ VERSION = "0.2.0"
4
4
  end
5
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.4
4
+ version: 0.2.0
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: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -32,17 +32,49 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '2.0'
37
+ version: '2.3'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '2.2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ - !ruby/object:Gem::Dependency
63
+ name: childprocess
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.2.5
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
44
76
  - !ruby/object:Gem::Version
45
- version: '2.0'
77
+ version: 0.2.5
46
78
  - !ruby/object:Gem::Dependency
47
79
  name: rspec
48
80
  requirement: !ruby/object:Gem::Requirement
@@ -103,12 +135,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
135
  - - ! '>='
104
136
  - !ruby/object:Gem::Version
105
137
  version: '0'
138
+ segments:
139
+ - 0
140
+ hash: -3920563354405383513
106
141
  required_rubygems_version: !ruby/object:Gem::Requirement
107
142
  none: false
108
143
  requirements:
109
144
  - - ! '>='
110
145
  - !ruby/object:Gem::Version
111
146
  version: '0'
147
+ segments:
148
+ - 0
149
+ hash: -3920563354405383513
112
150
  requirements: []
113
151
  rubyforge_project:
114
152
  rubygems_version: 1.8.24