ghostbuster 0.0.4 → 0.1.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.
- data/README.md +4 -3
- data/bin/setup-ghostbuster +2 -0
- data/ghost/test_ghostmore.coffee +1 -0
- data/lib/ghostbuster.coffee +32 -17
- data/lib/ghostbuster.rb +28 -3
- data/lib/ghostbuster/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ghostbuster
|
2
2
|
|
3
|
-
Automated browser testing via phantom.js, with all of the pain taken out!
|
3
|
+
Automated browser testing via phantom.js, with all of the pain taken out! That means you get a *real browser*, with a *real DOM*, and can do *real testing*!
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -8,7 +8,7 @@ To install first `gem install ghostbuster`. Once you've done that, you can run `
|
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
11
|
-
Once installed, you can simply use `ghostbuster path/to/tests` to run your tests. You should get some output that looks something
|
11
|
+
Once installed, you can simply use `ghostbuster path/to/tests` to run your tests. You should get some output that looks something like this.
|
12
12
|
|
13
13
|
~~~~
|
14
14
|
|
@@ -70,11 +70,12 @@ The closures passed for matching have access to the real DOM node, however, they
|
|
70
70
|
|
71
71
|
## Before and after
|
72
72
|
|
73
|
-
You can add an arbitrary number of before and after blocks to be run within the context of your test.
|
73
|
+
You can add an arbitrary number of before and after blocks to be run within the context of your test. Simply call `before` and `after` on your test to add them. You have to call @succeed in the before block to continue processing your test.
|
74
74
|
|
75
75
|
~~~~
|
76
76
|
phantom.test.before ->
|
77
77
|
# do some setup
|
78
|
+
@succeed()
|
78
79
|
|
79
80
|
phantom.test.after ->
|
80
81
|
# do some teardown
|
data/bin/setup-ghostbuster
CHANGED
@@ -16,6 +16,8 @@ when /darwin/
|
|
16
16
|
puts "Downloading and install phantom.js"
|
17
17
|
system("curl #{phantom_url} -O") or raise("Unable to download from #{phantom_url}")
|
18
18
|
system("open #{File.basename(phantom_url)}") or raise("Unable to open disk image")
|
19
|
+
puts("Giving time to mount the image...")
|
20
|
+
system("sleep 4")
|
19
21
|
end
|
20
22
|
system("cp -r /Volumes/phantomjs/phantomjs.app #{root}")
|
21
23
|
File.exist?("#{root}/phantomjs.app") or raise("Unable to copy phantomjs from your disk image")
|
data/ghost/test_ghostmore.coffee
CHANGED
data/lib/ghostbuster.coffee
CHANGED
@@ -19,8 +19,11 @@ class Test
|
|
19
19
|
waiting = ->
|
20
20
|
test.waitForAssertions(whenDone)
|
21
21
|
setTimeout waiting, 10
|
22
|
-
|
23
|
-
|
22
|
+
actuallyRun: -> true
|
23
|
+
run: (callback) ->
|
24
|
+
@runWithFunction(@testBody, callback)
|
25
|
+
runWithFunction: (fn, @callback) ->
|
26
|
+
fn.call(this)
|
24
27
|
get: (path, getCallback) ->
|
25
28
|
@waitForAssertions ->
|
26
29
|
test = this
|
@@ -176,7 +179,7 @@ class Body
|
|
176
179
|
class PendingTest
|
177
180
|
constructor: (@runner, @name) ->
|
178
181
|
run: (callback) -> callback('pending')
|
179
|
-
|
182
|
+
actuallyRun: -> false
|
180
183
|
class TestFile
|
181
184
|
constructor: (@suite, @name) ->
|
182
185
|
@tests = []
|
@@ -191,27 +194,39 @@ class TestFile
|
|
191
194
|
for test in @tests
|
192
195
|
throw("Identically named test already exists for name #{name} in #{@name}") if test.name == name
|
193
196
|
@tests.push new Test(this, name, body)
|
194
|
-
run: (callback) ->
|
197
|
+
run: (callback, idx) ->
|
195
198
|
throw "No root is defined" unless @root?
|
196
199
|
testFile = this
|
197
200
|
testStates = {}
|
198
201
|
nextTest = (count) ->
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
202
|
+
if count >= testFile.tests.length
|
203
|
+
testFile.report(testStates)
|
204
|
+
callback()
|
205
|
+
else
|
206
|
+
test = testFile.tests[count]
|
207
|
+
if test.actuallyRun()
|
208
|
+
processBefore = (idx, callback) ->
|
209
|
+
if testFile.befores[idx]?
|
210
|
+
test.runWithFunction testFile.befores[idx], ->
|
211
|
+
processBefore(idx + 1, callback)
|
212
|
+
else
|
213
|
+
callback()
|
214
|
+
return
|
215
|
+
processBefore 0, ->
|
216
|
+
try
|
217
|
+
test.run (state) ->
|
218
|
+
testStates[test.name] = state
|
219
|
+
nextTest(count + 1)
|
220
|
+
catch e
|
221
|
+
testFile.lastErrors[test.name] = e.toString()
|
222
|
+
testStates[test.name] = false
|
223
|
+
nextTest(count + 1)
|
224
|
+
finally
|
225
|
+
after.call(test) for after in testFile.afters
|
226
|
+
else
|
203
227
|
test.run (state) ->
|
204
228
|
testStates[test.name] = state
|
205
229
|
nextTest(count + 1)
|
206
|
-
else
|
207
|
-
testFile.report(testStates)
|
208
|
-
callback()
|
209
|
-
catch e
|
210
|
-
testFile.lastErrors[test.name] = e.toString()
|
211
|
-
testStates[test.name] = false
|
212
|
-
nextTest(count + 1)
|
213
|
-
finally
|
214
|
-
after.call(test) for before in testFile.afters
|
215
230
|
nextTest(0)
|
216
231
|
report: (testStates) ->
|
217
232
|
success = 0
|
data/lib/ghostbuster.rb
CHANGED
@@ -12,18 +12,23 @@ class Ghostbuster
|
|
12
12
|
@dir = File.directory?(@paths[0]) ? @paths[0] : File.dirname(@paths[0])
|
13
13
|
@ghost_lib = File.expand_path(File.join(File.dirname(__FILE__), "ghostbuster.coffee"))
|
14
14
|
@phantom_bin = File.join(ENV['HOME'], '.ghostbuster', 'phantomjs')
|
15
|
+
STDOUT.sync = true
|
15
16
|
end
|
16
17
|
|
17
18
|
def run
|
18
19
|
files = Array(@paths).map{|path| Dir[path].to_a}.flatten.map{|f| File.expand_path(f)}
|
19
20
|
status = 1
|
20
21
|
Dir.chdir(@dir) do
|
21
|
-
|
22
|
-
|
22
|
+
spinner "Starting server" do
|
23
|
+
sh "./start.sh"
|
24
|
+
sleep 2
|
25
|
+
end
|
23
26
|
begin
|
24
27
|
_, status = Process.waitpid2 fork { exec("#{@phantom_bin} #{@ghost_lib} #{files.join(' ')}") }
|
25
28
|
ensure
|
26
|
-
|
29
|
+
spinner "Stopping server" do
|
30
|
+
sh "./stop.sh"
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
29
34
|
exit(status)
|
@@ -32,4 +37,24 @@ class Ghostbuster
|
|
32
37
|
def self.run(path)
|
33
38
|
new(path).run
|
34
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def spinner(msg, &blk)
|
43
|
+
STDOUT.sync = true
|
44
|
+
print msg
|
45
|
+
print " "
|
46
|
+
spin = Thread.new do
|
47
|
+
i = 0
|
48
|
+
loop do
|
49
|
+
s = '/-\\|'
|
50
|
+
print s[i % 4].chr
|
51
|
+
i += 1
|
52
|
+
sleep 0.1
|
53
|
+
print "\b"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
yield
|
57
|
+
spin.kill
|
58
|
+
puts
|
59
|
+
end
|
35
60
|
end
|
data/lib/ghostbuster/version.rb
CHANGED
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
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.4
|
10
|
+
version: 0.1.0
|
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-08-
|
18
|
+
date: 2011-08-29 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|