guard-jasmine 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -8
- data/bin/guard-jasmine +7 -0
- data/lib/guard/jasmine.rb +20 -12
- data/lib/guard/jasmine/inspector.rb +13 -8
- data/lib/guard/jasmine/runner.rb +25 -13
- data/lib/guard/jasmine/version.rb +1 -1
- metadata +7 -6
data/README.md
CHANGED
@@ -112,8 +112,11 @@ Guard::Jasmine can be adapted to all kind of projects. Please read the
|
|
112
112
|
|
113
113
|
## Options
|
114
114
|
|
115
|
-
There
|
115
|
+
There are many options that can customize Guard::Jasmine to your needs.
|
116
116
|
|
117
|
+
### General options
|
118
|
+
|
119
|
+
The general options configures the environment that is needed to run Guard::Jasmine:
|
117
120
|
|
118
121
|
:jasmine_url => 'http://192.168.1.5/jasmine' # URL where Jasmine is served.
|
119
122
|
# default: http://127.0.0.1/jasmine
|
@@ -121,6 +124,10 @@ There following options can be passed to Guard::Jasmine:
|
|
121
124
|
:phantomjs_bin => '~/bin/phantomjs' # Path to phantomjs.
|
122
125
|
# default: '/usr/local/bin/phantomjs'
|
123
126
|
|
127
|
+
### Spec runner options
|
128
|
+
|
129
|
+
The spec runner options configures the behavior driven development (or BDD) cycle:
|
130
|
+
|
124
131
|
:all_on_start => false # Run all suites on start.
|
125
132
|
# default: true
|
126
133
|
|
@@ -130,20 +137,36 @@ There following options can be passed to Guard::Jasmine:
|
|
130
137
|
:all_after_pass => false # Run all suites after a suite has passed again after failing.
|
131
138
|
# default: true
|
132
139
|
|
133
|
-
|
140
|
+
The `:keep_failed` failed option remembers failed suites and not failed specs. The reason for this decision is to
|
141
|
+
avoid additional round trip time to request the Jasmine test runner for each single spec, which is mostly more expensive
|
142
|
+
than running a whole suite.
|
143
|
+
|
144
|
+
### Specdoc options
|
145
|
+
|
146
|
+
Guard::Jasmine can generate an RSpec like specdoc in the console after running the specs and you can set when it will
|
147
|
+
be shown in the console:
|
148
|
+
|
149
|
+
:specdoc => :always # Specdoc output options, either :always, :never or :failure
|
150
|
+
# default: :failure
|
151
|
+
|
152
|
+
With the option set to :always, the specdoc is shown with and without errors in your spec, whereas on with the option
|
153
|
+
set to :never, there is no output at all, instead just a summary of the spec run is shown. The default option :failure
|
154
|
+
shows the specdoc when at least one spec failed.
|
155
|
+
|
156
|
+
### System notifications options
|
157
|
+
|
158
|
+
These options affects what system notifications (growl, libnotify or notifu) are shown after a spec run:
|
159
|
+
|
160
|
+
:notifications => false # Show success and error notifications.
|
134
161
|
# default: true
|
135
162
|
|
136
|
-
:hide_success => true # Disable successful
|
163
|
+
:hide_success => true # Disable successful spec run notification.
|
137
164
|
# default: false
|
138
165
|
|
139
166
|
:max_error_notify => 5 # Maximum error notifications to show.
|
140
167
|
# default: 3
|
141
168
|
|
142
|
-
|
143
|
-
avoid to much round trip time to request the Jasmine test runner for each single spec, which is mostly more expensive
|
144
|
-
than running a whole suite.
|
145
|
-
|
146
|
-
### A note on Rails 2 and 3
|
169
|
+
## A note on Rails 2 and 3
|
147
170
|
|
148
171
|
This readme describes the use of Guard::Jasmine with Jasminerice through the asset pipeline, but it is not really
|
149
172
|
a requirement for Guard::Jasmine. As long as you serve the Jasmine test runner under a certain url,
|
data/bin/guard-jasmine
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
url = ARGV[1] || 'http://127.0.0.1:3000/jasmine'
|
4
|
+
script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'guard', 'jasmine', 'phantomjs', 'run-jasmine.coffee'))
|
5
|
+
|
6
|
+
puts "Run Jasmine at #{ url }"
|
7
|
+
puts `phantomjs #{ script } #{ url }`
|
data/lib/guard/jasmine.rb
CHANGED
@@ -16,6 +16,18 @@ module Guard
|
|
16
16
|
|
17
17
|
attr_accessor :last_run_failed, :last_failed_paths
|
18
18
|
|
19
|
+
DEFAULT_OPTIONS = {
|
20
|
+
:jasmine_url => 'http://localhost:3000/jasmine',
|
21
|
+
:phantomjs_bin => '/usr/local/bin/phantomjs',
|
22
|
+
:notification => true,
|
23
|
+
:hide_success => false,
|
24
|
+
:all_on_start => true,
|
25
|
+
:keep_failed => true,
|
26
|
+
:all_after_pass => true,
|
27
|
+
:max_error_notify => 3,
|
28
|
+
:specdoc => :failure
|
29
|
+
}
|
30
|
+
|
19
31
|
# Initialize Guard::Jasmine.
|
20
32
|
#
|
21
33
|
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
|
@@ -28,20 +40,13 @@ module Guard
|
|
28
40
|
# @option options [Boolean] :all_on_start run all suites on start
|
29
41
|
# @option options [Boolean] :keep_failed keep failed suites and add them to the next run again
|
30
42
|
# @option options [Boolean] :all_after_pass run all suites after a suite has passed again after failing
|
43
|
+
# @option options [Symbol] :specdoc options for the specdoc output, either :always, :never or :failure
|
31
44
|
#
|
32
45
|
def initialize(watchers = [], options = { })
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
:hide_success => false,
|
38
|
-
:all_on_start => true,
|
39
|
-
:keep_failed => true,
|
40
|
-
:all_after_pass => true,
|
41
|
-
:max_error_notify => 3
|
42
|
-
}
|
43
|
-
|
44
|
-
super(watchers, defaults.merge(options))
|
46
|
+
options = DEFAULT_OPTIONS.merge(options)
|
47
|
+
options[:specdoc] = :failure if ![:always, :never, :failure].include? options[:specdoc]
|
48
|
+
|
49
|
+
super(watchers, options)
|
45
50
|
|
46
51
|
self.last_run_failed = false
|
47
52
|
self.last_failed_paths = []
|
@@ -89,9 +94,12 @@ module Guard
|
|
89
94
|
# @return [Boolean] when running the changed specs was successful
|
90
95
|
#
|
91
96
|
def run_on_change(paths)
|
97
|
+
return false if Inspector.clean(paths).empty?
|
98
|
+
|
92
99
|
paths += self.last_failed_paths if options[:keep_failed]
|
93
100
|
|
94
101
|
passed, failed_specs = Runner.run(Inspector.clean(paths), options)
|
102
|
+
Inspector.clear
|
95
103
|
|
96
104
|
if passed
|
97
105
|
self.last_failed_paths = self.last_failed_paths - paths
|
@@ -16,11 +16,22 @@ module Guard
|
|
16
16
|
def clean(paths)
|
17
17
|
paths.uniq!
|
18
18
|
paths.compact!
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
if paths.include?('spec/javascripts')
|
21
|
+
paths = ['spec/javascripts']
|
22
|
+
else
|
23
|
+
paths = paths.select { |p| jasmine_spec?(p) }
|
24
|
+
end
|
25
|
+
|
21
26
|
paths
|
22
27
|
end
|
23
28
|
|
29
|
+
# Clears the list of Jasmine specs in this project.
|
30
|
+
#
|
31
|
+
def clear
|
32
|
+
@jasmine_specs = nil
|
33
|
+
end
|
34
|
+
|
24
35
|
private
|
25
36
|
|
26
37
|
# Tests if the file is valid.
|
@@ -43,12 +54,6 @@ module Guard
|
|
43
54
|
@jasmine_specs ||= Dir.glob('spec/**/*_spec.{js,js.coffee}')
|
44
55
|
end
|
45
56
|
|
46
|
-
# Clears the list of Jasmine specs in this project.
|
47
|
-
#
|
48
|
-
def clear_jasmine_specs
|
49
|
-
@jasmine_specs = nil
|
50
|
-
end
|
51
|
-
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
data/lib/guard/jasmine/runner.rb
CHANGED
@@ -21,6 +21,7 @@ module Guard
|
|
21
21
|
# @option options [Boolean] :notification show notifications
|
22
22
|
# @option options [Boolean] :hide_success hide success message notification
|
23
23
|
# @option options [Integer] :max_error_notify maximum error notifications to show
|
24
|
+
# @option options [Symbol] :specdoc options for the specdoc output, either :always, :never
|
24
25
|
# @return [Boolean, Array<String>] the status of the run and the failed files
|
25
26
|
#
|
26
27
|
def run(paths, options = { })
|
@@ -194,9 +195,12 @@ module Guard
|
|
194
195
|
message = "#{ specs } specs, #{ failures } failure#{ plural }\nin #{ time } seconds"
|
195
196
|
|
196
197
|
if failures != 0
|
197
|
-
|
198
|
+
show_specdoc(result) if options[:specdoc] != :never
|
199
|
+
Formatter.error(message)
|
200
|
+
notify_errors(result, options)
|
198
201
|
Formatter.notify(message, :title => 'Jasmine suite failed', :image => :failed, :priority => 2) if options[:notification]
|
199
202
|
else
|
203
|
+
show_specdoc(result) if options[:specdoc] == :always
|
200
204
|
Formatter.success(message)
|
201
205
|
Formatter.notify(message, :title => 'Jasmine suite passed') if options[:notification] && !options[:hide_success]
|
202
206
|
end
|
@@ -205,31 +209,39 @@ module Guard
|
|
205
209
|
# Specdoc like formatting of the result.
|
206
210
|
#
|
207
211
|
# @param [Hash] result the suite result
|
208
|
-
# @param [String] stats the status information
|
209
|
-
# @option options [Integer] :max_error_notify maximum error notifications to show
|
210
|
-
# @option options [Boolean] :hide_success hide success message notification
|
211
212
|
#
|
212
|
-
def
|
213
|
+
def show_specdoc(result)
|
213
214
|
result['suites'].each do |suite|
|
214
215
|
Formatter.suite_name("➥ #{ suite['description'] }")
|
215
216
|
|
216
217
|
suite['specs'].each_with_index do |spec, index|
|
217
218
|
if spec['passed']
|
218
|
-
Formatter.success(" ✔ #{ spec['description'] }")
|
219
|
+
Formatter.success(" ✔ #{ spec['description'] }")
|
219
220
|
else
|
220
221
|
Formatter.spec_failed(" ✘ #{ spec['description'] }")
|
221
222
|
Formatter.spec_failed(" ➤ #{ format_error_message(spec['error_message'], false) }")
|
222
|
-
if options[:max_error_notify] > index
|
223
|
-
Formatter.notify("#{ spec['description'] }: #{ format_error_message(spec['error_message'], true) }",
|
224
|
-
:title => 'Jasmine spec failed',
|
225
|
-
:image => :failed,
|
226
|
-
:priority => 2) if options[:notification]
|
227
|
-
end
|
228
223
|
end
|
229
224
|
end
|
230
225
|
end
|
226
|
+
end
|
231
227
|
|
232
|
-
|
228
|
+
# Specdoc like formatting of the result.
|
229
|
+
#
|
230
|
+
# @param [Hash] result the suite result
|
231
|
+
# @option options [Integer] :max_error_notify maximum error notifications to show
|
232
|
+
# @option options [Boolean] :hide_success hide success message notification
|
233
|
+
#
|
234
|
+
def notify_errors(result, options)
|
235
|
+
result['suites'].each do |suite|
|
236
|
+
suite['specs'].each_with_index do |spec, index|
|
237
|
+
if !spec['passed'] && options[:max_error_notify] > index
|
238
|
+
Formatter.notify("#{ spec['description'] }: #{ format_error_message(spec['error_message'], true) }",
|
239
|
+
:title => 'Jasmine spec failed',
|
240
|
+
:image => :failed,
|
241
|
+
:priority => 2) if options[:notification]
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
233
245
|
end
|
234
246
|
|
235
247
|
# Formats the error message.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-jasmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Kessler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: guard
|
@@ -128,13 +128,14 @@ dependencies:
|
|
128
128
|
description: Guard::Jasmine automatically tests your Jasmine specs on PhantomJS
|
129
129
|
email:
|
130
130
|
- michi@netzpiraten.ch
|
131
|
-
executables:
|
132
|
-
|
131
|
+
executables:
|
132
|
+
- guard-jasmine
|
133
133
|
extensions: []
|
134
134
|
|
135
135
|
extra_rdoc_files: []
|
136
136
|
|
137
137
|
files:
|
138
|
+
- bin/guard-jasmine
|
138
139
|
- lib/guard/jasmine/formatter.rb
|
139
140
|
- lib/guard/jasmine/inspector.rb
|
140
141
|
- lib/guard/jasmine/phantomjs/run-jasmine.coffee
|