guard-konacha 0.3.1 → 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTQ3Njc0ZWMxYmZjYzM1N2RlMjgzNzc4M2ZmYzUyZGQ5NmQ3NTkzZg==
5
+ data.tar.gz: !binary |-
6
+ ZjZjNmI1ZDMzMWIzZDZhNzY1ZjNiYmM2M2JiZjliZWM5NTRmZmExMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MmJmM2FlNTA1MTY1YzM2NDkxYzc2MWIzZjZmMWJmZDMwYTU5NWI1MGU2OGNj
10
+ Y2E1OWIxMWY3NTk0NzFlM2IzOTA1ZTk1MmVlMmE4NTRmYjZkYmZhZmEyYTEw
11
+ YzY2NDRlMWQ4YjkxYmYwNWY2NTJmMjcyZDU3NzQwZGJlOThmYWY=
12
+ data.tar.gz: !binary |-
13
+ MzJjMjFjMjk2YWQ2ZmY5MjA4MWFkMmUzNzk1N2FjYjZlY2ViZmJjMmFlNDMy
14
+ OWVhZDA5Zjc1Mzc0YjMyYjVjZjZjYzg2MDc2NzU1MDM1MzE1Zjc2MGFiYzI1
15
+ OTc3NzNhNGI5Mzc3ZmNiMmUyNDkzNWY4ZDI1OTljOGVmOGM1OTg=
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Alex Gibbons
1
+ Copyright (c) 2013 Alex Gibbons
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Readme.md CHANGED
@@ -1,55 +1,35 @@
1
- # Guard::Konacha [![Build Status](https://travis-ci.org/alexgb/guard-konacha.png)](https://travis-ci.org/alexgb/guard-konacha)
1
+ # Guard::Konacha [![Build Status](https://travis-ci.org/alexgb/guard-konacha.png?branch=master)](https://travis-ci.org/alexgb/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
 
5
5
  ## Install
6
6
 
7
- Install the gem:
8
-
9
- $ gem install guard-konacha
10
-
11
- Or add to your Gemfile:
7
+ If you haven't already, start by installing and configuring [Konacha](https://github.com/jfirebaugh/konacha). Then add the `guard-konacha` gem to your Gemfile:
12
8
 
9
+ # Gemfile
13
10
  gem 'guard-konacha'
14
11
 
15
- ## Usage
16
-
17
- Add guard definitions to your `Guardfile`
18
-
19
- guard :konacha do
20
- watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" }
21
- watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)$})
22
- end
12
+ And install
23
13
 
24
- ## Configuration
14
+ $ bundle install
25
15
 
26
- If your specs live outside of `spec/javascripts` then tell Konacha where to find them.
16
+ ## Setup
27
17
 
28
- guard :konacha, :spec_dir => 'spec/front-end' do
29
- # ...
30
- end
18
+ Add the default configurations to your Guardfile.
31
19
 
32
- If you want to use [capybara-webkit](https://github.com/thoughtbot/capybara-webkit) instead of the default selenium
33
- driver:
20
+ $ bundle exec guard init konacha
34
21
 
35
- require 'capybara-webkit'
36
- guard :konacha, :driver => :webkit do
37
- # ...
38
- end
22
+ ## Run
39
23
 
40
- Or use [Poltergeist](https://github.com/jonleighton/poltergeist):
24
+ And that's it. Your Konacha powered JavaScript tests will now run whenever your JavaScript assets or spec files change.
41
25
 
42
- require 'capybara/poltergeist'
43
- guard :konacha, :driver => :poltergeist do
44
- # ...
45
- end
26
+ $ bundle exec guard
46
27
 
47
- If you are running konacha:serve on a different host or port than the
48
- default `localhost` and `3500`, the configuration settings `:host` and `:port` will help you there.
28
+ ## Additionally
49
29
 
50
- ## Development
30
+ I recommend using the [capybara-webkit](https://github.com/thoughtbot/capybara-webkit) or [poltergeist](https://github.com/jonleighton/poltergeist) drivers rather than the default selenium based driver. See [Konacha instructions](https://github.com/jfirebaugh/konacha#configuration).
51
31
 
52
- This is a work in progress and could use some help.
32
+ To get system notifications see [Guard instructions](https://github.com/guard/guard/wiki/System-notifications).
53
33
 
54
34
  ## Contributors
55
35
 
data/lib/guard/konacha.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
+ require 'rails'
4
+ require 'konacha'
3
5
 
4
6
  module Guard
5
7
  class Konacha < Guard
6
8
 
7
9
  autoload :Runner, 'guard/konacha/runner'
10
+ autoload :Formatter, 'guard/konacha/formatter'
11
+ autoload :Server, 'guard/konacha/server'
12
+
8
13
  attr_accessor :runner
9
14
 
10
15
  def initialize(watchers=[], options={})
@@ -13,18 +18,11 @@ module Guard
13
18
  end
14
19
 
15
20
  def start
16
- runner.kill_konacha
17
- runner.launch_konacha("Start")
18
- runner.run_all_on_start
19
- end
20
-
21
- def reload
22
- runner.kill_konacha
23
- runner.launch_konacha("Reload")
21
+ runner.start
24
22
  end
25
23
 
26
24
  def run_all
27
- runner.run_all
25
+ runner.run
28
26
  end
29
27
 
30
28
  def run_on_changes(paths)
@@ -33,9 +31,5 @@ module Guard
33
31
  # for guard 1.0.x and earlier
34
32
  alias :run_on_change :run_on_changes
35
33
 
36
- def stop
37
- runner.kill_konacha
38
- end
39
-
40
34
  end
41
35
  end
@@ -0,0 +1,66 @@
1
+ module Guard
2
+ class Konacha
3
+ class Formatter < ::Konacha::Formatter
4
+
5
+ def initialize
6
+ super($stdout)
7
+ end
8
+
9
+ def reset
10
+ io.puts ""
11
+ @examples = []
12
+ end
13
+
14
+ def dump_summary(duration, example_count, failure_count, pending_count); end
15
+ def dump_failures; end
16
+ def dump_pending; end
17
+
18
+ def success?
19
+ failed_examples.empty?
20
+ end
21
+
22
+ def write_summary
23
+ io.puts ""
24
+ io.puts [
25
+ failed_examples_message,
26
+ pending_examples_message
27
+ ].reject(&:empty?).join("\n\n")
28
+ io.puts ""
29
+ io.puts summary_line
30
+ end
31
+
32
+ def summary_line
33
+ "#{examples.size} examples, #{failed_examples.size} failed, #{pending_examples.size} pending"
34
+ end
35
+
36
+
37
+ private
38
+
39
+
40
+ def failed_examples
41
+ @examples.select(&:failed?).select(&:exception)
42
+ end
43
+
44
+ def pending_examples
45
+ @examples.select(&:pending?)
46
+ end
47
+
48
+ def failed_examples_message
49
+ failed_examples.map { |e| failure_message(e) }.join("\n\n")
50
+ end
51
+
52
+ def failure_message(example)
53
+ " \xE2\x9C\x96 ".red + "#{example.metadata['path']}\n" + super
54
+ end
55
+
56
+ def pending_examples_message
57
+ pending_examples.map { |e| pending_message(e) }.join("\n\n")
58
+ end
59
+
60
+ def pending_message(example)
61
+ " \xE2\x97\x8B ".yellow + "#{example.metadata['path']}\n" + super
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -1,182 +1,89 @@
1
- require 'net/http'
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'
9
-
10
1
  module Guard
11
2
  class Konacha
12
3
  class Runner
13
4
 
14
5
  DEFAULT_OPTIONS = {
15
- :bundler => true,
16
- :spec_dir => 'spec/javascripts',
17
- :run_all => true,
18
- :all_on_start => true,
19
- :driver => :selenium,
20
- :host => 'localhost',
21
- :port => 3500,
6
+ :run_all_on_start => :true,
22
7
  :notification => true,
23
- :spawn_wait => 20
8
+ :rails_environment_file => './config/environment'
24
9
  }
25
10
 
26
- attr_reader :options
11
+ attr_reader :options, :formatter
27
12
 
28
13
  def initialize(options={})
29
14
  @options = DEFAULT_OPTIONS.merge(options)
30
- UI.info "Guard::Konacha Initialized"
31
- end
32
-
33
- def launch_konacha(action)
34
- UI.info "#{action}ing Konacha", :reset => true
35
- spawn_konacha
36
- end
37
-
38
- def kill_konacha
39
- clear_session!
40
- if @process
41
- @process.stop(5)
42
- UI.info "Konacha Stopped", :reset => true
43
- end
44
- end
45
-
46
- def run(paths=[])
47
- return UI.info("Konacha server not running") unless konacha_running?
48
15
 
49
- UI.info "Konacha Running: #{paths.empty? ? 'All tests' : paths.join(' ')}"
16
+ # Require project's rails environment file to load Konacha
17
+ # configuration
18
+ require_rails_environment
19
+ raise "Konacha not loaded" unless defined? ::Konacha
50
20
 
51
- urls = paths.map { |p| konacha_url(p) }
52
- urls = [konacha_url] if paths.empty?
21
+ # Custom formatter to handle multiple runs
22
+ @formatter = Formatter.new
23
+ ::Konacha.config.formatters = [@formatter]
53
24
 
54
- test_results = {
55
- :examples => 0,
56
- :failures => 0,
57
- :pending => 0,
58
- :duration => 0
59
- }
25
+ # Reusable session to increase performance
26
+ @session = Capybara::Session.new(::Konacha.driver, Server.new)
60
27
 
61
- urls.each_with_index do |url, index|
62
- individual_result = run_tests(url, paths[index])
28
+ ::Konacha.mode = :runner
63
29
 
64
- test_results[:examples] += individual_result[:examples]
65
- test_results[:failures] += individual_result[:failures]
66
- test_results[:pending] += individual_result[:pending]
67
- test_results[:duration] += individual_result[:duration]
68
- end
69
-
70
- result_line = "#{test_results[:examples]} examples, #{test_results[:failures]} failures"
71
- result_line << ", #{test_results[:pending]} pending" if test_results[:pending] > 0
72
- text = [
73
- result_line,
74
- "in #{"%.2f" % test_results[:duration]} seconds"
75
- ].join "\n"
76
-
77
- UI.info text if urls.length > 1
30
+ UI.info "Guard::Konacha Initialized"
31
+ end
78
32
 
79
- if @options[:notification]
80
- image = test_results[:failures] > 0 ? :failed : :success
81
- ::Guard::Notifier.notify(text, :title => 'Konacha Specs', :image => image )
82
- end
33
+ def start
34
+ run if options[:run_all_on_start]
83
35
  end
84
36
 
85
- EMPTY_RESULT = {
86
- :examples => 0,
87
- :failures => 0,
88
- :pending => 0,
89
- :duration => 0,
90
- }
37
+ def run(paths = [''])
38
+ formatter.reset
91
39
 
92
- def run_tests(url, path)
93
- session.reset!
94
- unless valid_spec? url
95
- UI.warning "No spec found for: #{path}"
96
- return EMPTY_RESULT
40
+ paths.each do |path|
41
+ runner.run konacha_path(path)
97
42
  end
98
43
 
99
- runner = ::Konacha::Runner.new session
100
- runner.run url
101
- return {
102
- :examples => runner.reporter.example_count,
103
- :failures => runner.reporter.failure_count,
104
- :pending => runner.reporter.pending_count,
105
- :duration => runner.reporter.duration
106
- }
44
+ formatter.write_summary
45
+ notify
107
46
  rescue => e
108
- UI.error e.inspect
109
- @session = nil
110
- end
111
-
112
- def run_all
113
- run if @options[:run_all]
47
+ UI.error(e)
114
48
  end
115
49
 
116
- def run_all_on_start
117
- run_all if @options[:all_on_start]
118
- end
119
50
 
120
51
  private
121
52
 
122
- def konacha_url(path = nil)
123
- url_path = path.gsub(/^#{@options[:spec_dir]}\/?/, '').gsub(/\.coffee$/, '').gsub(/\.js$/, '') unless path.nil?
124
- "#{konacha_base_url}/#{url_path}?mode=runner&unique=#{unique_id}"
125
- end
126
-
127
- def unique_id
128
- "#{Time.now.to_i}#{rand(100)}"
129
- end
130
-
131
- def session
132
- UI.info "Starting Konacha-Capybara session using #{@options[:driver]} driver, this can take a few seconds..." if @session.nil?
133
- @session ||= Capybara::Session.new @options[:driver]
134
- end
135
53
 
136
- def clear_session!
137
- return unless @session
138
- @session.reset!
139
- @session = nil
140
- end
141
-
142
- def spawn_konacha_command
143
- cmd_parts = ''
144
- cmd_parts << "bundle exec " if bundler?
145
- cmd_parts << "rake konacha:serve"
146
- cmd_parts.split
147
- end
148
-
149
- def spawn_konacha
150
- unless @process
151
- @process = ChildProcess.build(*spawn_konacha_command)
152
- @process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
153
- @process.start
154
-
155
- Timeout::timeout(@options[:spawn_wait]) do
156
- until konacha_running?
157
- sleep(0.2)
54
+ def require_rails_environment
55
+ if @options[:rails_environment_file]
56
+ require @options[:rails_environment_file]
57
+ else
58
+ dir = '.'
59
+ while File.expand_path(dir) != '/' do
60
+ env_file = File.join(dir, 'config/environment.rb')
61
+ if File.exist?(env_file)
62
+ require File.expand_path(env_file)
63
+ break
158
64
  end
65
+ dir = File.join(dir, '..')
159
66
  end
160
67
  end
161
68
  end
162
69
 
163
- def konacha_base_url
164
- "http://#{@options[:host]}:#{@options[:port]}"
70
+ def runner
71
+ ::Konacha::Runner.new(@session)
165
72
  end
166
73
 
167
- def konacha_running?
168
- Net::HTTP.get_response(URI.parse(konacha_base_url))
169
- rescue Errno::ECONNREFUSED
74
+ def konacha_path(path)
75
+ '/' + path.gsub(/^#{::Konacha.config[:spec_dir]}\/?/, '').gsub(/\.coffee$/, '').gsub(/\.js$/, '')
170
76
  end
171
77
 
172
- def bundler?
173
- @bundler ||= options[:bundler] != false && File.exist?("#{Dir.pwd}/Gemfile")
78
+ def unique_id
79
+ "#{Time.now.to_i}#{rand(100)}"
174
80
  end
175
81
 
176
- def valid_spec? url
177
- session.visit url
178
- konacha_spec = session.evaluate_script('typeof window.top.Konacha')
179
- konacha_spec == 'object'
82
+ def notify
83
+ if options[:notification]
84
+ image = @formatter.success? ? :success : :failed
85
+ ::Guard::Notifier.notify(@formatter.summary_line, :title => "Konacha Specs", :image => image)
86
+ end
180
87
  end
181
88
 
182
89
  end
@@ -0,0 +1,32 @@
1
+ module Guard
2
+ class Konacha
3
+ class Server < Rack::Builder
4
+
5
+ def self.new
6
+ super do
7
+ use CacheBuster
8
+ run ::Konacha.application
9
+ end
10
+ end
11
+
12
+ class CacheBuster
13
+
14
+ def initialize(app)
15
+ @app = app
16
+ end
17
+
18
+ def call(env)
19
+ status, headers, body = @app.call(env)
20
+
21
+ headers.delete('Last-Modified')
22
+ headers.delete('ETag')
23
+ headers.delete('Cache-Control')
24
+
25
+ [status, headers, body]
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -1,7 +1,9 @@
1
1
  ### Guard::Konacha
2
2
  # available options:
3
- # - :spec_dir, defaults to 'spec/javascripts'
4
- # - :driver, defaults to :selenium
3
+ # - :run_all_on_start, defaults to :true
4
+ # - :notification, defaults to :true
5
+ # - :rails_environment_file, location of rails environment file,
6
+ # should be able to find it automatically
5
7
  guard :konacha do
6
8
  watch(%r{^app/assets/javascripts/(.*)\.js(\.coffee)?$}) { |m| "#{m[1]}_spec.js" }
7
9
  watch(%r{^spec/javascripts/.+_spec(\.js|\.js\.coffee)$})
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module KonachaVersion
3
- VERSION = "0.3.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-konacha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Gibbons
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-12 00:00:00.000000000 Z
11
+ date: 2013-08-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: guard
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,55 +27,34 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: konacha
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
37
- version: '2.3'
33
+ version: '3.0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
45
- version: '2.3'
40
+ version: '3.0'
46
41
  - !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
42
+ name: rspec
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
45
  - - ! '>='
68
46
  - !ruby/object:Gem::Version
69
- version: 0.2.5
70
- type: :runtime
47
+ version: '2.13'
48
+ type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
52
  - - ! '>='
76
53
  - !ruby/object:Gem::Version
77
- version: 0.2.5
54
+ version: '2.13'
78
55
  - !ruby/object:Gem::Dependency
79
- name: rspec
56
+ name: timecop
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
59
  - - ! '>='
84
60
  - !ruby/object:Gem::Version
@@ -86,15 +62,13 @@ dependencies:
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
66
  - - ! '>='
92
67
  - !ruby/object:Gem::Version
93
68
  version: '0'
94
69
  - !ruby/object:Gem::Dependency
95
- name: timecop
70
+ name: simplecov
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
73
  - - ! '>='
100
74
  - !ruby/object:Gem::Version
@@ -102,15 +76,13 @@ dependencies:
102
76
  type: :development
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
80
  - - ! '>='
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
83
  - !ruby/object:Gem::Dependency
111
- name: simplecov
84
+ name: poltergeist
112
85
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
86
  requirements:
115
87
  - - ! '>='
116
88
  - !ruby/object:Gem::Version
@@ -118,7 +90,6 @@ dependencies:
118
90
  type: :development
119
91
  prerelease: false
120
92
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
93
  requirements:
123
94
  - - ! '>='
124
95
  - !ruby/object:Gem::Version
@@ -130,14 +101,18 @@ executables: []
130
101
  extensions: []
131
102
  extra_rdoc_files: []
132
103
  files:
104
+ - lib/guard/konacha/formatter.rb
133
105
  - lib/guard/konacha/runner.rb
106
+ - lib/guard/konacha/server.rb
134
107
  - lib/guard/konacha/templates/Guardfile
135
108
  - lib/guard/konacha/version.rb
136
109
  - lib/guard/konacha.rb
137
110
  - LICENSE
138
111
  - Readme.md
139
112
  homepage: https://github.com/alexgb/guard-konacha
140
- licenses: []
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
141
116
  post_install_message:
142
117
  rdoc_options:
143
118
  - --charset=UTF-8
@@ -146,27 +121,19 @@ rdoc_options:
146
121
  require_paths:
147
122
  - lib
148
123
  required_ruby_version: !ruby/object:Gem::Requirement
149
- none: false
150
124
  requirements:
151
125
  - - ! '>='
152
126
  - !ruby/object:Gem::Version
153
127
  version: '0'
154
- segments:
155
- - 0
156
- hash: -145410006532593905
157
128
  required_rubygems_version: !ruby/object:Gem::Requirement
158
- none: false
159
129
  requirements:
160
130
  - - ! '>='
161
131
  - !ruby/object:Gem::Version
162
132
  version: '0'
163
- segments:
164
- - 0
165
- hash: -145410006532593905
166
133
  requirements: []
167
134
  rubyforge_project:
168
- rubygems_version: 1.8.25
135
+ rubygems_version: 2.0.3
169
136
  signing_key:
170
- specification_version: 3
171
- summary: Guard gem for Konacha
137
+ specification_version: 4
138
+ summary: Guard plugin for Konacha
172
139
  test_files: []