guard-jasmine 1.18.3 → 1.19.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23bb53cca2e5b5ce98b0b78b80f5bc7562efead1
4
- data.tar.gz: 0a7e7b695bc1e37873951d24e851512598eab59a
3
+ metadata.gz: 0d2c707960fcbd14e19cf91a60bf45ff6d7a4cdd
4
+ data.tar.gz: c57544a68c99bd17d8504421ceb167b7d0096ebe
5
5
  SHA512:
6
- metadata.gz: a7f629189012aba7a3668d774b51b499e356d87714bca03abe83dc3604875eb4e8d4c03c1c760b80d5395e6412c49777b53647432b232a409006c6d2fede7a81
7
- data.tar.gz: a6799461e50bf9cf5971256f38d91585da535af35df17233c93e6f0a83235e5c27df67bfdaf3585d8f8fc347cff572cd88c6afeb60e2b0ef42c7f54878daa598
6
+ metadata.gz: 933c8df094af29fdbf81a565112fd0d064e02630aee67091ebe8a8bfa4c566dbab3d548aabc4efbeb31ed7556058ee39990a6bb9dce4e191e55b81abc4321651
7
+ data.tar.gz: 297af7cc9c7563040174b72a036ddc278ba02dc1135af5734017209ada53253304a5a5a727575efed81a9af96c5ed701dbbf1b3efb4ed551bcdb421568f65c3e
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Guard::Jasmine automatically tests your Jasmine specs when files are modified.
4
4
 
5
- Tested on MRI Ruby 1.9.2, 1.9.3, 2.0.0 and the latest version of JRuby.
5
+ Tested on MRI Ruby 1.9.3, 2.0.0 and the latest version of JRuby.
6
6
 
7
7
  If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard`
8
8
  (irc.freenode.net).
@@ -158,7 +158,7 @@ Now you can access `/jasmine` when you start your Rails server normally.
158
158
  2. Configure a mount point in your application's `routes.rb` (please refer to the [jasmine-rails][] documentation for more details):
159
159
 
160
160
  ```ruby
161
- mount JasmineRails::Engine => '/spec' if defined?(JasmineRails)
161
+ mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
162
162
  ```
163
163
 
164
164
  3. Configure **Guard::Jasmine** to reference the mount point in your `Guardfile`:
@@ -672,6 +672,7 @@ Options:
672
672
  -b, [--bin=BIN] # The location of the PhantomJS binary
673
673
  -d, [--spec-dir=SPEC_DIR] # The directory with the Jasmine specs
674
674
  # Default: spec/javascripts
675
+ -l, [--line-number=N] # The line which identifies the spec to be run
675
676
  -u, [--url=URL] # The url of the Jasmine test runner_options
676
677
  # Default: nil
677
678
  -t, [--timeout=N] # The maximum time in seconds to wait for the spec
data/lib/guard/jasmine.rb CHANGED
@@ -1,15 +1,14 @@
1
1
  require 'net/http'
2
2
 
3
3
  require 'guard'
4
- require 'guard/guard'
5
- require 'guard/watcher'
4
+ require 'guard/plugin'
6
5
 
7
6
  module Guard
8
7
 
9
8
  # The Jasmine guard that gets notifications about the following
10
- # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`.
9
+ # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_modifications`.
11
10
  #
12
- class Jasmine < Guard
11
+ class Jasmine < Plugin
13
12
 
14
13
  require 'guard/jasmine/coverage'
15
14
  require 'guard/jasmine/inspector'
@@ -57,7 +56,6 @@ module Guard
57
56
 
58
57
  # Initialize Guard::Jasmine.
59
58
  #
60
- # @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
61
59
  # @param [Hash] options the options for the Guard
62
60
  # @option options [String] :server the server to use, either :auto, :none, :webrick, :mongrel, :thin, :jasmine_gem, or a custom rake task
63
61
  # @option options [String] :server_env the server environment to use, for example :development, :test
@@ -89,7 +87,7 @@ module Guard
89
87
  # @option options [Symbol] :lines_threshold options for the statement lines threshold
90
88
  # @option options [Hash] :run_all options overwrite options when run all specs
91
89
  #
92
- def initialize(watchers = [], options = { })
90
+ def initialize(options = { })
93
91
  options[:server_mount] ||= defined?(JasmineRails) ? '/specs' : '/jasmine'
94
92
 
95
93
  options = DEFAULT_OPTIONS.merge(options)
@@ -104,7 +102,7 @@ module Guard
104
102
 
105
103
  self.run_all_options = options.delete(:run_all) || { }
106
104
 
107
- super(watchers, options)
105
+ super(options)
108
106
 
109
107
  self.last_run_failed = false
110
108
  self.last_failed_paths = []
@@ -112,7 +110,7 @@ module Guard
112
110
 
113
111
  # Gets called once when Guard starts.
114
112
  #
115
- # @raise [:task_has_failed] when run_on_change has failed
113
+ # @raise [:task_has_failed] when start has failed
116
114
  #
117
115
  def start
118
116
  if Jasmine.phantomjs_bin_valid?(options[:phantomjs_bin])
@@ -137,7 +135,7 @@ module Guard
137
135
 
138
136
  # Gets called when the Guard should reload itself.
139
137
  #
140
- # @raise [:task_has_failed] when run_on_change has failed
138
+ # @raise [:task_has_failed] when reload has failed
141
139
  #
142
140
  def reload
143
141
  self.last_run_failed = false
@@ -146,7 +144,7 @@ module Guard
146
144
 
147
145
  # Gets called when all specs should be run.
148
146
  #
149
- # @raise [:task_has_failed] when run_on_change has failed
147
+ # @raise [:task_has_failed] when run_all has failed
150
148
  #
151
149
  def run_all
152
150
  passed, failed_specs = Runner.run([options[:spec_dir]], options.merge(self.run_all_options))
@@ -160,9 +158,9 @@ module Guard
160
158
  # Gets called when watched paths and files have changes.
161
159
  #
162
160
  # @param [Array<String>] paths the changed paths and files
163
- # @raise [:task_has_failed] when run_on_change has failed
161
+ # @raise [:task_has_failed] when run_on_modifications has failed
164
162
  #
165
- def run_on_changes(paths)
163
+ def run_on_modifications(paths)
166
164
  specs = options[:keep_failed] ? paths + self.last_failed_paths : paths
167
165
  specs = Inspector.clean(specs, options) if options[:clean]
168
166
  return false if specs.empty?
@@ -65,6 +65,11 @@ module Guard
65
65
  aliases: '-d',
66
66
  desc: 'The directory with the Jasmine specs'
67
67
 
68
+ method_option :line_number,
69
+ type: :numeric,
70
+ aliases: '-l',
71
+ desc: 'The line which identifies the spec to be run'
72
+
68
73
  method_option :url,
69
74
  type: :string,
70
75
  aliases: '-u',
@@ -166,6 +171,7 @@ module Guard
166
171
  runner_options = {}
167
172
  runner_options[:port] = options.port || CLI.find_free_server_port
168
173
  runner_options[:spec_dir] = options.spec_dir || (File.exists?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec')
174
+ runner_options[:line_number] = options.line_number
169
175
  runner_options[:server] = options.server.to_sym == :auto ? ::Guard::Jasmine::Server.detect_server(runner_options[:spec_dir]) : options.server.to_sym
170
176
  runner_options[:server_mount] = options.mount || (defined?(JasmineRails) ? '/specs' : '/jasmine')
171
177
  runner_options[:jasmine_url] = options.url || "http://localhost:#{ runner_options[:port] }#{ options.server.to_sym == :jasmine_gem ? '/' : runner_options[:server_mount] }"
@@ -41,7 +41,7 @@ module Guard
41
41
  notify_start_message(paths, options)
42
42
 
43
43
  results = paths.inject([]) do |results, file|
44
- results << evaluate_response(run_jasmine_spec(file, options), file, options) if File.exist?(file)
44
+ results << evaluate_response(run_jasmine_spec(file, options), file, options) if File.exist?(file_and_line_number_parts(file)[0])
45
45
 
46
46
  results
47
47
  end.compact
@@ -141,9 +141,7 @@ module Guard
141
141
  end
142
142
 
143
143
  # The suite name must be extracted from the spec that
144
- # will be run. This is done by parsing from the head of
145
- # the spec file until the first `describe` function is
146
- # found.
144
+ # will be run.
147
145
  #
148
146
  # @param [String] file the spec file
149
147
  # @param [Hash] options the options for the execution
@@ -153,16 +151,97 @@ module Guard
153
151
  def query_string_for_suite(file, options)
154
152
  return '' if file == options[:spec_dir]
155
153
 
156
- query_string = ''
154
+ query_string = query_string_for_suite_from_line_number(file, options)
155
+
156
+ unless query_string
157
+ query_string = query_string_for_suite_from_first_describe(file, options)
158
+ end
159
+
160
+ query_string = query_string ? "?spec=#{ query_string }" : ''
161
+
162
+ URI.encode(query_string)
163
+ end
164
+
165
+ # When providing a line number by either the option or by
166
+ # a number directly after the file name the suite is extracted
167
+ # fromt the corresponding line number in the file.
168
+ #
169
+ # @param [String] file the spec file
170
+ # @param [Hash] options the options for the execution
171
+ # @option options [Fixnum] :line_number the line number to run
172
+ # @return [String] the suite name
173
+ #
174
+ def query_string_for_suite_from_line_number(file, options)
175
+ file_name, line_number = file_and_line_number_parts(file)
176
+ line_number ||= options[:line_number]
177
+
178
+ if line_number
179
+ lines = it_and_describe_lines(file_name, 0, line_number)
180
+ last = lines.pop
181
+
182
+ last_indentation = last[/^\s*/].length
183
+ # keep only lines with lower indentation
184
+ lines.delete_if { |x| x[/^\s*/].length >= last_indentation }
185
+ # remove all 'it'
186
+ lines.delete_if { |x| x =~ /^\s*it/ }
157
187
 
188
+ lines << last
189
+ lines.map { |x| spec_title(x) }.join(' ')
190
+ end
191
+ end
192
+
193
+ # The suite name must be extracted from the spec that
194
+ # will be run. This is done by parsing from the head of
195
+ # the spec file until the first `describe` function is
196
+ # found.
197
+ #
198
+ # @param [String] file the spec file
199
+ # @param [Hash] options the options for the execution
200
+ # @return [String] the suite name
201
+ #
202
+ def query_string_for_suite_from_first_describe(file, options)
158
203
  File.foreach(file) do |line|
159
204
  if line =~ /describe\s*[("']+(.*?)["')]+/
160
- query_string = "?spec=#{ $1 }"
161
- break
205
+ return $1
162
206
  end
163
207
  end
208
+ end
164
209
 
165
- URI.encode(query_string)
210
+ # Splits the file name into the physical file name
211
+ # and the line number if present. E.g.:
212
+ # 'some_spec.js.coffee:10' -> ['some_spec.js.coffee', 10].
213
+ #
214
+ # If the line number is missing the second part of the
215
+ # returned array is `nil`.
216
+ #
217
+ # @param [String] file the spec file
218
+ # @return [Array] `[file_name, line_number]`
219
+ #
220
+ def file_and_line_number_parts(file)
221
+ match = file.match(/^(.+?)(?::(\d+))?$/)
222
+ [match[1], match[2].nil? ? nil : match[2].to_i]
223
+ end
224
+
225
+ # Returns all lines of the file that are either a
226
+ # 'describe' or a 'it' declaration.
227
+ #
228
+ # @param [String] file the spec file
229
+ # @param [Numeric] from the first line in the range
230
+ # @param [Numeric] to the last line in the range
231
+ # @Return [Array] the line contents
232
+ #
233
+ def it_and_describe_lines(file, from, to)
234
+ File.readlines(file)[from, to].
235
+ select { |x| x =~ /^\s*(it|describe)/ }
236
+ end
237
+
238
+ # Extracts the title of a 'description' or a 'it' declaration.
239
+ #
240
+ # @param [String] the line content
241
+ # @return [String] the extracted title
242
+ #
243
+ def spec_title(line)
244
+ line[/['"](.+?)['"]/, 1]
166
245
  end
167
246
 
168
247
  # Evaluates the JSON response that the PhantomJS script
@@ -1,6 +1,6 @@
1
1
  module Guard
2
2
  module JasmineVersion
3
3
  # Guard::Jasmine version that is used for the Gem specification
4
- VERSION = '1.18.3'
4
+ VERSION = '1.19.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-jasmine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.3
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kessler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-31 00:00:00.000000000 Z
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.0
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: childprocess
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tilt
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Guard::Jasmine automatically tests your Jasmine specs on PhantomJS
@@ -140,17 +140,17 @@ require_paths:
140
140
  - lib
141
141
  required_ruby_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - '>='
148
+ - - ">="
149
149
  - !ruby/object:Gem::Version
150
150
  version: 1.3.6
151
151
  requirements: []
152
152
  rubyforge_project: guard-jasmine
153
- rubygems_version: 2.0.7
153
+ rubygems_version: 2.1.11
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Guard gem for headless testing with Jasmine