ghostbuster 0.3.3 → 0.3.4
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.
- data/Rakefile +3 -3
- data/bin/setup-ghostbuster +11 -14
- data/lib/ghostbuster.coffee +50 -38
- data/lib/ghostbuster.rb +16 -4
- data/lib/ghostbuster/config.rb +2 -1
- data/lib/ghostbuster/version.rb +1 -1
- data/test/non_working_ghost/test_ghost.coffee +5 -0
- metadata +16 -16
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ STDOUT.sync = true
|
|
4
4
|
|
5
5
|
namespace :test do
|
6
6
|
[:working_via_bin, :working_via_rake].each do |task_name|
|
7
|
-
desc "Run test for `working' test suite (
|
7
|
+
desc "Run test for `working' test suite (#{task_name})"
|
8
8
|
task task_name do
|
9
9
|
print "#{task_name} ... "
|
10
10
|
Dir.chdir("test/working_ghost") do
|
@@ -18,7 +18,7 @@ namespace :test do
|
|
18
18
|
end
|
19
19
|
begin
|
20
20
|
matcher.each{|m| out[m] or raise("Couldn't match for #{m.inspect}")}
|
21
|
-
raise("There are a weird number of screenshots") unless Dir['*.png'].to_a.size ==
|
21
|
+
raise("There are a weird number of screenshots") unless Dir['*.png'].to_a.size == 15
|
22
22
|
exit
|
23
23
|
rescue
|
24
24
|
puts $!.message
|
@@ -36,7 +36,7 @@ namespace :test do
|
|
36
36
|
task :non_working do
|
37
37
|
print "non_working_ghost ... "
|
38
38
|
Dir.chdir("test/non_working_ghost") do
|
39
|
-
matcher = [/0 success,
|
39
|
+
matcher = [/0 success, 9 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/]
|
40
40
|
fork {
|
41
41
|
ENV['BUNDLE_GEMFILE'] = File.expand_path("./Gemfile")
|
42
42
|
`bundle install`
|
data/bin/setup-ghostbuster
CHANGED
@@ -3,30 +3,27 @@
|
|
3
3
|
case RUBY_PLATFORM
|
4
4
|
when /darwin/
|
5
5
|
require 'fileutils'
|
6
|
-
puts "Creating ghostbuster directory in your home"
|
7
6
|
root = File.expand_path(File.join(ENV['HOME'], '.ghostbuster'))
|
8
7
|
cache = File.expand_path(File.join(root, 'cache'))
|
9
|
-
unless File.exist?(File.join(root, 'version')) && File.read(File.join(root, 'version')) == '
|
8
|
+
unless File.exist?(File.join(root, 'version')) && File.read(File.join(root, 'version')) == '2'
|
9
|
+
puts "Creating ghostbuster directory in your home"
|
10
10
|
FileUtils.rm_rf(root)
|
11
11
|
FileUtils.mkdir_p(root)
|
12
12
|
FileUtils.mkdir_p(cache)
|
13
|
-
phantom_url = "http://phantomjs.googlecode.com/files/phantomjs-1.
|
13
|
+
phantom_url = "http://phantomjs.googlecode.com/files/phantomjs-1.3.0-macosx-static-x86.zip"
|
14
14
|
unless File.exist?(File.join(cache, File.basename(phantom_url)))
|
15
15
|
Dir.chdir(cache) do
|
16
|
-
puts "Downloading and
|
16
|
+
puts "Downloading and installing phantom.js"
|
17
17
|
system("curl #{phantom_url} -O") or raise("Unable to download from #{phantom_url}")
|
18
|
-
system("
|
19
|
-
puts("Giving time to mount the image...")
|
20
|
-
system("sleep 4")
|
18
|
+
system("unzip #{File.basename(phantom_url)}") or raise("Unable to unzip archive")
|
21
19
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
File.open("#{root}/version", 'w') {|f| f << '1' }
|
27
|
-
else
|
28
|
-
puts "Already installed and at the right version"
|
20
|
+
File.exist?("#{cache}/phantomjs-1.3.0/bin/phantomjs") or raise("Unable to copy phantomjs from your disk image")
|
21
|
+
system("ln -s #{cache}/phantomjs-1.3.0/bin/phantomjs #{root}/phantomjs") or raise("Unable to copy phantomjs from your disk image")
|
22
|
+
File.open("#{root}/version", 'w') {|f| f << '2' }
|
23
|
+
puts "Done installing!"
|
29
24
|
end
|
25
|
+
else
|
26
|
+
puts "Already installed and at the right version"
|
30
27
|
end
|
31
28
|
else
|
32
29
|
puts "I don't know how to install for RUBY_PLATFORM #{RUBY_PLATFORM}"
|
data/lib/ghostbuster.coffee
CHANGED
@@ -123,19 +123,27 @@ class Body
|
|
123
123
|
"
|
124
124
|
@test.page.evaluate(input)
|
125
125
|
|
126
|
-
click: (selector,
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
126
|
+
click: (selector, opts) ->
|
127
|
+
opts ||= {}
|
128
|
+
test = @test
|
129
|
+
@test.assert opts, (withValue) ->
|
130
|
+
idx = opts.index || 0
|
131
|
+
eval "
|
132
|
+
var evaluator = function() {
|
133
|
+
var targets = document.querySelectorAll('#{selector}'),
|
134
|
+
evt = document.createEvent('MouseEvents'),
|
135
|
+
idx = #{idx};
|
136
|
+
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
137
|
+
if (idx < targets.length) {
|
138
|
+
targets[idx].dispatchEvent(evt);
|
139
|
+
return true;
|
140
|
+
} else {
|
141
|
+
alert('Couldn\\'t find element #{idx} for selector #{selector}');
|
142
|
+
return false;
|
143
|
+
}
|
144
|
+
};
|
145
|
+
"
|
146
|
+
withValue @page.evaluate(evaluator)
|
139
147
|
|
140
148
|
assertCount: (selector, opts, assertionCallback) ->
|
141
149
|
unless assertionCallback?
|
@@ -339,33 +347,37 @@ class TestSuite
|
|
339
347
|
@failure += failure
|
340
348
|
@pending += pending
|
341
349
|
run: ->
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
350
|
+
if phantom.version.major == 1 and phantom.version.minor == 3
|
351
|
+
@screenshots = @args[0] == 'true'
|
352
|
+
@screenshot_x = @args[1]
|
353
|
+
@screenshot_y = @args[2]
|
354
|
+
@screenshot_dir = @args[3]
|
355
|
+
count = 4
|
356
|
+
suite = this
|
357
|
+
runNextTest = ->
|
358
|
+
if suite.args.length == count
|
359
|
+
console.log "#{suite.success} success, #{suite.failure} failure, #{suite.pending} pending"
|
360
|
+
phantom.exit (if suite.failure == 0 then 0 else 1)
|
361
|
+
else
|
362
|
+
testFile = suite.args[count]
|
363
|
+
phantom.test = new TestFile(suite, testFile)
|
364
|
+
if phantom.injectJs(testFile)
|
365
|
+
try
|
366
|
+
phantom.test.run ->
|
367
|
+
count++
|
368
|
+
runNextTest()
|
369
|
+
catch e
|
370
|
+
console.log "For \033[1m#{testFile}\033[0m"
|
371
|
+
console.log " \033[31m\u2717\033[0m #{e.toString()}"
|
372
|
+
suite.failure++
|
358
373
|
count++
|
359
374
|
runNextTest()
|
360
|
-
|
361
|
-
console.log "
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
else
|
367
|
-
console.log "Unable to load #{testFile}"
|
368
|
-
runNextTest()
|
375
|
+
else
|
376
|
+
console.log "Unable to load #{testFile}"
|
377
|
+
runNextTest()
|
378
|
+
else
|
379
|
+
console.log "Phantom version must be 1.3.x"
|
380
|
+
phantom.exit 1
|
369
381
|
|
370
382
|
if phantom.args.length == 0
|
371
383
|
console.log("You need to specify a test file")
|
data/lib/ghostbuster.rb
CHANGED
@@ -25,19 +25,31 @@ class Ghostbuster
|
|
25
25
|
Dir.chdir(@dir) do
|
26
26
|
load_config
|
27
27
|
spinner "Starting server" do
|
28
|
-
|
28
|
+
if @config.verbose
|
29
|
+
puts `#{@config.start_command}`
|
30
|
+
raise unless $!.success?
|
31
|
+
else
|
32
|
+
sh @config.start_command
|
33
|
+
end
|
29
34
|
sleep 2
|
30
35
|
end
|
31
36
|
begin
|
32
37
|
_, status = Process.waitpid2 fork {
|
33
38
|
exec("#{@config.phantom_bin} #{@ghost_lib} #{@config.screenshots?} #{@config.screenshot_x} #{@config.screenshot_y} #{@temporary_screenshot_dir} #{Dir[@config.pattern].to_a.join(' ')}")
|
34
39
|
}
|
35
|
-
|
36
|
-
|
40
|
+
if status.success? && @config.screenshots?
|
41
|
+
spinner "Copying screenshots" do
|
42
|
+
compress_and_copy_screenshots
|
43
|
+
end
|
37
44
|
end
|
38
45
|
ensure
|
39
46
|
spinner "Stopping server" do
|
40
|
-
|
47
|
+
if @config.verbose
|
48
|
+
puts `#{@config.stop_command}`
|
49
|
+
raise unless $!.success?
|
50
|
+
else
|
51
|
+
sh @config.stop_command
|
52
|
+
end
|
41
53
|
end
|
42
54
|
if @config.screenshots?
|
43
55
|
spinner "Cleaning up temporary screenshots" do
|
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
|
3
|
+
attr_accessor :pattern, :screenshot_dir, :start_command, :stop_command, :phantom_bin, :temp_dir, :verbose
|
4
4
|
attr_reader :screenshot_x, :screenshot_y
|
5
5
|
def initialize(path_to_file = nil)
|
6
6
|
@config_file = path_to_file || './Ghostfile'
|
@@ -9,6 +9,7 @@ class Ghostbuster
|
|
9
9
|
@phantom_bin = File.join(ENV['HOME'], '.ghostbuster', 'phantomjs')
|
10
10
|
@screenshot_dir = "."
|
11
11
|
@screenshots = true
|
12
|
+
@verbose = false
|
12
13
|
@temp_dir = "/tmp"
|
13
14
|
@start_command, @stop_command = "./start.sh", "./stop.sh"
|
14
15
|
if File.exist?(@config_file)
|
data/lib/ghostbuster/version.rb
CHANGED
@@ -6,6 +6,11 @@ phantom.test.add "Bad link traversal", ->
|
|
6
6
|
@body.assertLocation('/not-correct')
|
7
7
|
@succeed()
|
8
8
|
|
9
|
+
phantom.test.add "Bad click selector", ->
|
10
|
+
@get '/', ->
|
11
|
+
@body.click 'i-just-made-this-up'
|
12
|
+
@succeed()
|
13
|
+
|
9
14
|
phantom.test.add "Form input not equal", ->
|
10
15
|
@get '/form', ->
|
11
16
|
@body.input "#in", "this is my input"
|
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Hull
|
@@ -15,12 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: thin
|
22
23
|
prerelease: false
|
23
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
@@ -31,12 +32,12 @@ dependencies:
|
|
31
32
|
- 2
|
32
33
|
- 11
|
33
34
|
version: 1.2.11
|
34
|
-
requirement: *id001
|
35
|
-
name: thin
|
36
35
|
type: :development
|
36
|
+
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
38
39
|
prerelease: false
|
39
|
-
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
42
|
requirements:
|
42
43
|
- - ~>
|
@@ -47,12 +48,12 @@ dependencies:
|
|
47
48
|
- 8
|
48
49
|
- 7
|
49
50
|
version: 0.8.7
|
50
|
-
requirement: *id002
|
51
|
-
name: rake
|
52
51
|
type: :development
|
52
|
+
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
54
55
|
prerelease: false
|
55
|
-
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
57
|
none: false
|
57
58
|
requirements:
|
58
59
|
- - ~>
|
@@ -63,12 +64,12 @@ dependencies:
|
|
63
64
|
- 0
|
64
65
|
- 14
|
65
66
|
version: 1.0.14
|
66
|
-
requirement: *id003
|
67
|
-
name: bundler
|
68
67
|
type: :development
|
68
|
+
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
70
71
|
prerelease: false
|
71
|
-
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
73
|
none: false
|
73
74
|
requirements:
|
74
75
|
- - ">="
|
@@ -77,9 +78,8 @@ dependencies:
|
|
77
78
|
segments:
|
78
79
|
- 0
|
79
80
|
version: "0"
|
80
|
-
requirement: *id004
|
81
|
-
name: sinatra
|
82
81
|
type: :development
|
82
|
+
version_requirements: *id004
|
83
83
|
description: Integration testing ftw.
|
84
84
|
email:
|
85
85
|
- joshbuddy@gmail.com
|