guard-jasmine 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -152,11 +152,16 @@ featured browser environment.
152
152
 
153
153
  ## Development
154
154
 
155
- - Documentation hosted at [RubyDoc](http://rubydoc.info/gems/guard-jasmine/file/README.md)
156
- - Source hosted at [GitHub](https://github.com/netzpirat/guard-Jasmine)
157
- - Report issues and feature requests to [GitHub Issues](https://github.com/netzpirat/guard-Jasmine/issues)
155
+ - Documentation hosted at [RubyDoc](http://rubydoc.info/gems/guard-jasmine/file/README.md).
156
+ - Source hosted at [GitHub](https://github.com/netzpirat/guard-Jasmine).
157
+ - Report issues and feature requests to [GitHub Issues](https://github.com/netzpirat/guard-Jasmine/issues).
158
158
 
159
- Pull requests are very welcome! Make sure your patches are well tested.
159
+ Pull requests are very welcome! Please try to follow these simple "rules", though:
160
+
161
+ - Please create a topic branch for every separate change you make.
162
+ - Make sure your patches are well tested.
163
+ - Update the README (if applicable).
164
+ - Please **do not change** the version number.
160
165
 
161
166
  For questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard`
162
167
  (irc.freenode.net).
@@ -1,32 +1,73 @@
1
1
  module Guard
2
2
  class Jasmine
3
+
4
+ # The Guard::Jasmine formatter collects console and
5
+ # system notification methods and enhances them with
6
+ # some color information.
7
+ #
3
8
  module Formatter
4
9
  class << self
5
10
 
11
+ # Print an info message to the console.
12
+ #
13
+ # @param [String] message the message to print
14
+ # @param [Hash] options the output options
15
+ # @option options [Boolean] :reset reset the UI
16
+ #
6
17
  def info(message, options = { })
7
18
  ::Guard::UI.info(message, options)
8
19
  end
9
20
 
21
+ # Print a debug message to the console.
22
+ #
23
+ # @param [String] message the message to print
24
+ # @param [Hash] options the output options
25
+ # @option options [Boolean] :reset reset the UI
26
+ #
10
27
  def debug(message, options = { })
11
28
  ::Guard::UI.debug(message, options)
12
29
  end
13
30
 
31
+ # Print a red error message to the console.
32
+ #
33
+ # @param [String] message the message to print
34
+ # @param [Hash] options the output options
35
+ # @option options [Boolean] :reset reset the UI
36
+ #
14
37
  def error(message, options = { })
15
38
  ::Guard::UI.error(color(message, ';31'), options)
16
39
  end
17
40
 
41
+ # Print a green success message to the console.
42
+ #
43
+ # @param [String] message the message to print
44
+ # @param [Hash] options the output options
45
+ # @option options [Boolean] :reset reset the UI
46
+ #
18
47
  def success(message, options = { })
19
48
  ::Guard::UI.info(color(message, ';32'), options)
20
49
  end
21
50
 
51
+ # Outputs a system notification.
52
+ #
53
+ # @param [String] message the message to print
54
+ # @param [Hash] options the output options
55
+ # @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
56
+ # @option options [String] :title the title of the system notification
57
+ #
22
58
  def notify(message, options = { })
23
59
  ::Guard::Notifier.notify(message, options)
24
60
  end
25
61
 
26
62
  private
27
63
 
64
+ # Print a info message to the console.
65
+ #
66
+ # @param [String] test the text to colorize
67
+ # @param [String] color_code the color code
68
+ #
28
69
  def color(text, color_code)
29
- ::Guard::UI.send(:color_enabled?) ? "\e[0#{color_code}m#{text}\e[0m" : text
70
+ ::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
30
71
  end
31
72
 
32
73
  end
@@ -1,60 +1,65 @@
1
- ##
2
- # Wait until the test condition is true or a timeout occurs. Useful for waiting
3
- # on a server response or for a ui change (fadeIn, etc.) to occur.
1
+ # Wait until the test condition is true or a timeout occurs.
2
+ #
3
+ # @param [Function] testFx the condition that evaluates to a boolean
4
+ # @param [Function] onReady the action when the condition is fulfilled
5
+ # @param [Number] timeOutMillis the max amount of time to wait
4
6
  #
5
- # @param testFx javascript condition that evaluates to a boolean,
6
- # it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
7
- # as a callback function.
8
- # @param onReady what to do when testFx condition is fulfilled,
9
- # it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
10
- # as a callback function.
11
- # @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
12
- ##
13
7
  waitFor = (testFx, onReady, timeOutMillis=3000) ->
14
8
  start = new Date().getTime()
15
9
  condition = false
16
- f = ->
10
+ wait = ->
17
11
  if (new Date().getTime() - start < timeOutMillis) and not condition
18
- # If not time-out yet and condition not yet fulfilled
19
- condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code
12
+ condition = (if typeof testFx is 'string' then eval testFx else testFx())
20
13
  else
21
14
  if not condition
22
- # If condition still not fulfilled (timeout but condition is 'false')
23
- console.log JSON.stringify { error: "Timeout requesting Jasmine test runner!" }
15
+ console.log "JasmineResult: #{ JSON.stringify { error: "Timeout requesting Jasmine test runner!" } }"
24
16
  phantom.exit(1)
25
17
  else
26
- # Condition fulfilled (timeout and/or condition is 'true')
27
- if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled
28
- clearInterval interval #< Stop this interval
18
+ if typeof onReady is 'string' then eval onReady else onReady()
19
+ clearInterval interval
29
20
 
30
- interval = setInterval f, 100 #< repeat check every 100ms
21
+ interval = setInterval wait, 100
31
22
 
23
+ # Check arguments of the script.
24
+ #
32
25
  if phantom.args.length isnt 1
33
- console.log JSON.stringify { error: "Wrong usage of PhantomJS script!" }
26
+ console.log "JasmineResult: #{ JSON.stringify { error: "Wrong usage of PhantomJS script!" } }"
34
27
  phantom.exit()
28
+ else
29
+ url = phantom.args[0]
35
30
 
36
31
  page = new WebPage()
37
- page.onConsoleMessage = (msg) -> console.log msg
38
32
 
39
- url = phantom.args[0]
33
+ # Output the Jasmine test runner result as JSON object.
34
+ # Ignore all other calls to console.log
35
+ #
36
+ page.onConsoleMessage = (msg) -> console.log(RegExp.$1) if /^JasmineResult: (.*)$/.test(msg)
40
37
 
38
+ # Open web page and run the Jasmine test runner
39
+ #
41
40
  page.open url, (status) ->
41
+
42
42
  if status isnt 'success'
43
- console.log JSON.stringify { error: "Unable to access Jasmine specs at #{ url }" }
43
+
44
+ console.log "JasmineResult: #{ JSON.stringify { error: "Unable to access Jasmine specs at #{ url }" } }"
44
45
  phantom.exit()
45
46
 
46
47
  else
47
- waitFor ->
48
- page.evaluate ->
49
- if document.body.querySelector '.finished-at' then true else false
48
+ # Wait until the Jasmine test is run
49
+ waitFor -> page.evaluate -> if document.body.querySelector '.finished-at' then true else false
50
50
  , ->
51
+ # Jasmine test runner has finished, extract the result from the DOM
51
52
  page.evaluate ->
53
+
54
+ # JSON response to Guard::Jasmine
52
55
  result = {
53
56
  suites: []
54
57
  }
55
58
 
56
59
  # Extract runner stats from the HTML
57
60
  stats = /(\d+) specs, (\d+) failures? in (\d+.\d+)s/.exec document.body.querySelector('.description').innerText
61
+
62
+ # Add stats to the result
58
63
  result['stats'] = {
59
64
  specs: parseInt stats[1]
60
65
  failures: parseInt stats[2]
@@ -64,12 +69,15 @@ page.open url, (status) ->
64
69
  # Extract failed suites
65
70
  for failedSuite in document.body.querySelectorAll 'div.jasmine_reporter > div.suite.failed'
66
71
  description = failedSuite.querySelector('a.description')
72
+
73
+ # Add suite information to the result
67
74
  suite = {
68
75
  description: description.innerText
69
76
  filter: description.getAttribute('href')
70
77
  specs: []
71
78
  }
72
79
 
80
+ # Collect information about each **failing** spec
73
81
  for failedSpec in failedSuite.querySelectorAll 'div.spec.failed'
74
82
  spec = {
75
83
  description: failedSpec.querySelector('a.description').getAttribute 'title'
@@ -79,6 +87,7 @@ page.open url, (status) ->
79
87
 
80
88
  result['suites'].push suite
81
89
 
82
- console.log JSON.stringify result, undefined, 2
90
+ # Write result as JSON string that is parsed by Guard::Jasmine
91
+ console.log "JasmineResult: #{ JSON.stringify result, undefined, 2 }"
83
92
 
84
93
  phantom.exit()
@@ -1,5 +1,6 @@
1
1
  module Guard
2
2
  module JasmineVersion
3
- VERSION = '0.2.0'
3
+ # Guard::Jasmine version that is used for the Gem specification
4
+ VERSION = '0.2.1'
4
5
  end
5
6
  end
metadata CHANGED
@@ -1,168 +1,135 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-jasmine
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Michael Kessler
14
- autorequire:
9
+ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-07 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-08 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
21
16
  name: guard
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ version_requirements: &2422 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
24
22
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- - 4
32
- version: "0.4"
23
+ requirement: *2422
24
+ prerelease: false
33
25
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
26
+ - !ruby/object:Gem::Dependency
36
27
  name: multi_json
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
28
+ version_requirements: &2440 !ruby/object:Gem::Requirement
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 17
44
- segments:
45
- - 1
46
- - 0
47
- - 3
31
+ - !ruby/object:Gem::Version
48
32
  version: 1.0.3
33
+ none: false
34
+ requirement: *2440
35
+ prerelease: false
49
36
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
37
+ - !ruby/object:Gem::Dependency
52
38
  name: bundler
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
39
+ version_requirements: &2456 !ruby/object:Gem::Requirement
40
+ requirements:
57
41
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 15
60
- segments:
61
- - 1
62
- - 0
63
- version: "1.0"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ none: false
45
+ requirement: *2456
46
+ prerelease: false
64
47
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
48
+ - !ruby/object:Gem::Dependency
67
49
  name: guard-rspec
68
- prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
50
+ version_requirements: &2474 !ruby/object:Gem::Requirement
51
+ requirements:
72
52
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- - 4
78
- version: "0.4"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ none: false
56
+ requirement: *2474
57
+ prerelease: false
79
58
  type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
59
+ - !ruby/object:Gem::Dependency
82
60
  name: rspec
83
- prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
61
+ version_requirements: &2490 !ruby/object:Gem::Requirement
62
+ requirements:
87
63
  - - ~>
88
- - !ruby/object:Gem::Version
89
- hash: 15
90
- segments:
91
- - 2
92
- - 6
93
- version: "2.6"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.6'
66
+ none: false
67
+ requirement: *2490
68
+ prerelease: false
94
69
  type: :development
95
- version_requirements: *id005
96
- - !ruby/object:Gem::Dependency
70
+ - !ruby/object:Gem::Dependency
97
71
  name: yard
98
- prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
100
- none: false
101
- requirements:
72
+ version_requirements: &2506 !ruby/object:Gem::Requirement
73
+ requirements:
102
74
  - - ~>
103
- - !ruby/object:Gem::Version
104
- hash: 7
105
- segments:
106
- - 0
107
- - 7
108
- - 2
75
+ - !ruby/object:Gem::Version
109
76
  version: 0.7.2
77
+ none: false
78
+ requirement: *2506
79
+ prerelease: false
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ name: kramdown
83
+ version_requirements: &2522 !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.13.3
88
+ none: false
89
+ requirement: *2522
90
+ prerelease: false
110
91
  type: :development
111
- version_requirements: *id006
112
92
  description: Guard::Jasmine automatically tests your Jasmine specs on PhantomJS
113
- email:
93
+ email:
114
94
  - michi@netzpiraten.ch
115
95
  executables: []
116
-
117
96
  extensions: []
118
-
119
97
  extra_rdoc_files: []
120
-
121
- files:
98
+ files:
99
+ - lib/guard/jasmine.rb
122
100
  - lib/guard/jasmine/formatter.rb
123
101
  - lib/guard/jasmine/inspector.rb
124
- - lib/guard/jasmine/phantomjs/run-jasmine.coffee
125
102
  - lib/guard/jasmine/runner.rb
126
- - lib/guard/jasmine/templates/Guardfile
127
103
  - lib/guard/jasmine/version.rb
128
- - lib/guard/jasmine.rb
104
+ - lib/guard/jasmine/phantomjs/run-jasmine.coffee
105
+ - lib/guard/jasmine/templates/Guardfile
129
106
  - LICENSE.MIT
130
107
  - LICENSE.BSD
131
108
  - README.md
109
+ has_rdoc: true
132
110
  homepage: http://github.com/netzpirat/guard-jasmine
133
111
  licenses: []
134
-
135
- post_install_message:
112
+ post_install_message:
136
113
  rdoc_options: []
137
-
138
- require_paths:
114
+ require_paths:
139
115
  - lib
140
- required_ruby_version: !ruby/object:Gem::Requirement
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
141
121
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
- version: "0"
149
- required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- hash: 23
155
- segments:
156
- - 1
157
- - 3
158
- - 6
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
159
126
  version: 1.3.6
127
+ none: false
160
128
  requirements: []
161
-
162
129
  rubyforge_project: guard-jasmine
163
- rubygems_version: 1.8.6
164
- signing_key:
130
+ rubygems_version: 1.5.1
131
+ signing_key:
165
132
  specification_version: 3
166
133
  summary: Guard gem for headless testing with Jasmine
167
134
  test_files: []
168
-
135
+ ...