ghostbuster 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/Rakefile +3 -3
- data/lib/ghostbuster.coffee +62 -1
- data/lib/ghostbuster.rb +1 -1
- data/lib/ghostbuster/config.rb +2 -1
- data/lib/ghostbuster/version.rb +1 -1
- data/test/non_working_ghost/test_ghost.coffee +6 -1
- data/test/server1/views/index.erb +1 -0
- data/test/working_ghost/test_ghost.coffee +21 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -40,6 +40,10 @@ To set the command for starting your server use:
|
|
40
40
|
|
41
41
|
ghost.start_command "./start.sh"
|
42
42
|
|
43
|
+
To set the timeout in seconds for the start_command to complete use:
|
44
|
+
|
45
|
+
ghost.start_wait = 2 # this is the default
|
46
|
+
|
43
47
|
To set the command for stopping your server use:
|
44
48
|
|
45
49
|
ghost.stop_command "./stop.sh"
|
@@ -118,6 +122,13 @@ This location will be relative to your root if it doesn't start with "http". You
|
|
118
122
|
|
119
123
|
This will click the nth element matching the selector. If no index is specified it uses the first one found.
|
120
124
|
|
125
|
+
### clickFollow
|
126
|
+
|
127
|
+
*Arguments*: selector, [index or options]
|
128
|
+
|
129
|
+
This will click the nth element matching the selector and assert the location changed. If no index is specified it uses the first one found.
|
130
|
+
If no path option is given, it will merely assert that the location changed.
|
131
|
+
|
121
132
|
### input
|
122
133
|
|
123
134
|
*Arguments*: selector, text
|
@@ -158,6 +169,12 @@ The callback will be called for each matching DOM element for the selector. The
|
|
158
169
|
|
159
170
|
This assertion will attempt to match the current browser location. If your location does not start with `http`, it will be considered relative to the root of your test.
|
160
171
|
|
172
|
+
### refuteLocation
|
173
|
+
|
174
|
+
*Arguments*: location, [options]
|
175
|
+
|
176
|
+
This assertion will attempt to refute the current browser location. If your location does not start with `http`, it will be considered relative to the root of your test.
|
177
|
+
|
161
178
|
### assertCount
|
162
179
|
|
163
180
|
*Arguments*: selector, [options], callback
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ namespace :test do
|
|
8
8
|
task task_name do
|
9
9
|
print "#{task_name} ... "
|
10
10
|
Dir.chdir("test/working_ghost") do
|
11
|
-
matcher = [/
|
11
|
+
matcher = [/13 success, 0 failure, 1 pending/]
|
12
12
|
fork {
|
13
13
|
ENV['BUNDLE_GEMFILE'] = File.expand_path("./Gemfile")
|
14
14
|
`bundle install`
|
@@ -19,7 +19,7 @@ namespace :test do
|
|
19
19
|
begin
|
20
20
|
matcher.each{|m| out[m] or raise("Couldn't match for #{m.inspect}")}
|
21
21
|
real_size = Dir['*.png'].to_a.size
|
22
|
-
expected_size =
|
22
|
+
expected_size = 21
|
23
23
|
raise("There are a weird number of screenshots, expected #{expected_size}, got #{real_size}") unless expected_size == real_size
|
24
24
|
exit
|
25
25
|
rescue
|
@@ -38,7 +38,7 @@ namespace :test do
|
|
38
38
|
task :non_working do
|
39
39
|
print "non_working_ghost ... "
|
40
40
|
Dir.chdir("test/non_working_ghost") do
|
41
|
-
matcher = [/0 success,
|
41
|
+
matcher = [/0 success, 10 failure, 1 pending/, /Bad link traversal\s+Assert location failed: Excepted http:\/\/127\.0\.0\.1:4567\/not-correct, got http:\/\/127\.0\.0\.1:4567\//, /Form input not equal\s+Assert first for selector #out did not meet expectations/, /To an invalid URL\s+The request for http:\/\/127\.0\.0\.1:this-url-is-invalid failed/, /This test will explode!\s+I hate you!/, /This test has no succeed\s+This test took too long/, /This test has a custom assertion name\s+Assert first "custom assertion name" did not meet expectations/, /Bad click selector\s+Couldn't find element 0 for selector i-just-made-this-up/, /Bad click follow\s+Assert not location failed: Excepted not http:\/\/127\.0\.0\.1:4567\/, got http:\/\/127\.0\.0\.1:4567\//]
|
42
42
|
fork {
|
43
43
|
ENV['BUNDLE_GEMFILE'] = File.expand_path("./Gemfile")
|
44
44
|
`bundle install`
|
data/lib/ghostbuster.coffee
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
class Test
|
2
2
|
constructor: (@runner, @name, @maxDuration, @testBody) ->
|
3
3
|
@page = new WebPage()
|
4
|
+
@resources = []
|
5
|
+
resources = @resources
|
6
|
+
@page.onResourceRequested = (req) ->
|
7
|
+
resources.push(req.url)
|
8
|
+
@page.onResourceReceived = (req) ->
|
9
|
+
while (index = resources.indexOf(req.url)) != -1
|
10
|
+
resources.splice(index, 1)
|
4
11
|
if @runner.useScreenshots()
|
5
12
|
@page.viewportSize = @runner.viewportDimensions()
|
6
13
|
@page.onConsoleMessage = (msg) ->
|
@@ -21,7 +28,7 @@ class Test
|
|
21
28
|
@runner.lastErrors[@name] = error
|
22
29
|
waitForAssertions: (whenDone) ->
|
23
30
|
@stopTestTimer()
|
24
|
-
if @assertions.length == 0
|
31
|
+
if @assertions.length == 0 and @resources.length == 0
|
25
32
|
@startTestTimer()
|
26
33
|
whenDone.call(this)
|
27
34
|
else
|
@@ -147,6 +154,39 @@ class Body
|
|
147
154
|
"
|
148
155
|
withValue @page.evaluate(evaluator)
|
149
156
|
|
157
|
+
clickFollow: (selector, opts) ->
|
158
|
+
opts ||= {}
|
159
|
+
test = @test
|
160
|
+
@test.assert opts, (withValue) ->
|
161
|
+
idx = opts.index || 0
|
162
|
+
currentLocation = @page.evaluate -> return window.location.href
|
163
|
+
eval "
|
164
|
+
var evaluator = function() {
|
165
|
+
var targets = document.querySelectorAll('#{selector}'),
|
166
|
+
evt = document.createEvent('MouseEvents'),
|
167
|
+
idx = #{idx};
|
168
|
+
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
169
|
+
if (idx < targets.length) {
|
170
|
+
targets[idx].dispatchEvent(evt);
|
171
|
+
return true;
|
172
|
+
} else {
|
173
|
+
alert('Couldn\\'t find element #{idx} for selector #{selector}');
|
174
|
+
return false;
|
175
|
+
}
|
176
|
+
};
|
177
|
+
"
|
178
|
+
val = @page.evaluate(evaluator)
|
179
|
+
if val?
|
180
|
+
if opts.path?
|
181
|
+
test.body.assertLocation(opts.path)
|
182
|
+
else
|
183
|
+
test.body.refuteLocation(currentLocation)
|
184
|
+
page = @page
|
185
|
+
fn = -> withValue(val)
|
186
|
+
setTimeout fn, 50
|
187
|
+
else
|
188
|
+
withValue @page.evaluate(evaluator)
|
189
|
+
|
150
190
|
assertCount: (selector, opts, assertionCallback) ->
|
151
191
|
unless assertionCallback?
|
152
192
|
assertionCallback = opts
|
@@ -197,6 +237,27 @@ class Body
|
|
197
237
|
"
|
198
238
|
withValue @page.evaluate(fn)
|
199
239
|
|
240
|
+
refuteLocation: (path, opts) ->
|
241
|
+
opts ||= {}
|
242
|
+
test = @test
|
243
|
+
location = @test.runner.normalizePath(path)
|
244
|
+
@test.assert opts, (withValue) ->
|
245
|
+
assertionDescription = if opts.name then " \"#{opts.name}\"" else ""
|
246
|
+
alerter = if test.getLastError()? then "" else "alert('Assert not location#{assertionDescription} failed: Excepted not #{location}, got '+currentLocation);"
|
247
|
+
eval "
|
248
|
+
var fn = function() {
|
249
|
+
var currentLocation = window.location.href;
|
250
|
+
if (window.location.href !== '#{location}') {
|
251
|
+
console.log('succeeded with ' +window.location.href);
|
252
|
+
return true;
|
253
|
+
} else {
|
254
|
+
#{alerter}
|
255
|
+
return false;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
"
|
259
|
+
withValue @page.evaluate(fn)
|
260
|
+
|
200
261
|
assertFirst: (selector, opts, assertionCallback) ->
|
201
262
|
unless assertionCallback?
|
202
263
|
assertionCallback = opts
|
data/lib/ghostbuster.rb
CHANGED
data/lib/ghostbuster/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Ghostbuster
|
2
2
|
class Config
|
3
|
-
attr_accessor :pattern, :screenshot_dir, :start_command, :stop_command, :phantom_bin, :temp_dir, :verbose
|
3
|
+
attr_accessor :pattern, :screenshot_dir, :start_command, :stop_command, :phantom_bin, :temp_dir, :verbose, :start_wait
|
4
4
|
attr_reader :screenshot_x, :screenshot_y
|
5
5
|
def initialize(path_to_file = nil)
|
6
6
|
@config_file = path_to_file || './Ghostfile'
|
@@ -12,6 +12,7 @@ class Ghostbuster
|
|
12
12
|
@verbose = false
|
13
13
|
@temp_dir = "/tmp"
|
14
14
|
@start_command, @stop_command = "./start.sh", "./stop.sh"
|
15
|
+
@start_wait = 2
|
15
16
|
if File.exist?(@config_file)
|
16
17
|
instance_eval File.read(@config_file), @config_file, 1
|
17
18
|
end
|
data/lib/ghostbuster/version.rb
CHANGED
@@ -5,7 +5,12 @@ phantom.test.add "Bad link traversal", ->
|
|
5
5
|
@body.click 'a'
|
6
6
|
@body.assertLocation('/not-correct')
|
7
7
|
@succeed()
|
8
|
-
|
8
|
+
|
9
|
+
phantom.test.add "Bad click follow", ->
|
10
|
+
@get '/', ->
|
11
|
+
@body.clickFollow '#hiya'
|
12
|
+
@succeed()
|
13
|
+
|
9
14
|
phantom.test.add "Bad click selector", ->
|
10
15
|
@get '/', ->
|
11
16
|
@body.click 'i-just-made-this-up'
|
@@ -6,8 +6,11 @@ phantom.test.add "Simple index", ->
|
|
6
6
|
p.innerHTML == 'This is my paragraph'
|
7
7
|
@body.assertAll 'ul li', (li, idx) ->
|
8
8
|
li.innerHTML == "List item #{idx + 1}"
|
9
|
-
@body.assertCountAndAll 'a',
|
10
|
-
|
9
|
+
@body.assertCountAndAll 'a', 2, (a, idx) ->
|
10
|
+
if idx == 0
|
11
|
+
a.href == 'http://127.0.0.1:4567/form'
|
12
|
+
else if idx == 1
|
13
|
+
a.href == 'javascript:%20false;'
|
11
14
|
@succeed()
|
12
15
|
|
13
16
|
phantom.test.add "Simple slow index", ->
|
@@ -28,3 +31,19 @@ phantom.test.add "Link traversal", ->
|
|
28
31
|
@body.assertLocation('/form')
|
29
32
|
@succeed()
|
30
33
|
|
34
|
+
phantom.test.add "Link traversal with counter-case", ->
|
35
|
+
@get '/', ->
|
36
|
+
@body.click 'a'
|
37
|
+
@body.refuteLocation('/')
|
38
|
+
@succeed()
|
39
|
+
|
40
|
+
phantom.test.add "Click follow", ->
|
41
|
+
@get '/', ->
|
42
|
+
@body.clickFollow 'a'
|
43
|
+
@succeed()
|
44
|
+
|
45
|
+
phantom.test.add "Click follow with positive case", ->
|
46
|
+
@get '/', ->
|
47
|
+
@body.clickFollow 'a', path: "/form"
|
48
|
+
@succeed()
|
49
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghostbuster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Hull
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|