ghostbuster 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/ghost/test_ghostmore.coffee +14 -0
- data/lib/ghostbuster.coffee +18 -7
- data/lib/ghostbuster/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -67,3 +67,15 @@ The available assertions are:
|
|
67
67
|
* _assertLocation_ : This asserts the current browser location
|
68
68
|
|
69
69
|
The closures passed for matching have access to the real DOM node, however, they do not have any access to the outside context. They must return true if the assertion is passed, anything else will be interpreted as failure.
|
70
|
+
|
71
|
+
## Before and after
|
72
|
+
|
73
|
+
You can add an arbitrary number of before and after blocks to be run within the context of your test. Simple call `before` and `after` on your test to add them.
|
74
|
+
|
75
|
+
~~~~
|
76
|
+
phantom.test.before ->
|
77
|
+
# do some setup
|
78
|
+
|
79
|
+
phantom.test.after ->
|
80
|
+
# do some teardown
|
81
|
+
~~~~
|
data/ghost/test_ghostmore.coffee
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
phantom.test.root = "http://127.0.0.1:4567"
|
2
2
|
|
3
|
+
phantom.test.before ->
|
4
|
+
@var = 'sample'
|
5
|
+
|
3
6
|
phantom.test.add "Simple form", ->
|
4
7
|
@get '/form', ->
|
5
8
|
@succeed()
|
@@ -19,3 +22,14 @@ phantom.test.add "Slow form", ->
|
|
19
22
|
@body.assertFirst '#out', total: 3, (out) ->
|
20
23
|
out.innerHTML == 'this is my input'
|
21
24
|
@succeed()
|
25
|
+
|
26
|
+
phantom.test.add "Before block var", ->
|
27
|
+
@get '/form', ->
|
28
|
+
@body.input "#in", @var
|
29
|
+
@body.click "#btn"
|
30
|
+
@body.assertFirst '#out', (out) ->
|
31
|
+
out.innerHTML == 'sample'
|
32
|
+
@succeed()
|
33
|
+
|
34
|
+
phantom.test.add "This test will explode!", ->
|
35
|
+
throw "I hate you!"
|
data/lib/ghostbuster.coffee
CHANGED
@@ -181,27 +181,38 @@ class TestFile
|
|
181
181
|
constructor: (@suite, @name) ->
|
182
182
|
@tests = []
|
183
183
|
@lastErrors = {}
|
184
|
+
@befores = []
|
185
|
+
@afters = []
|
184
186
|
normalizePath: (path) -> if path.match(/^http/) then path else "#{@root}#{path}"
|
185
187
|
addPending: (name, body) -> @tests.push new PendingTest(this, name)
|
188
|
+
before: (body) -> @befores.push(body)
|
189
|
+
after: (body) -> @afters.push(body)
|
186
190
|
add: (name, body) ->
|
187
191
|
for test in @tests
|
188
192
|
throw("Identically named test already exists for name #{name} in #{@name}") if test.name == name
|
189
193
|
@tests.push new Test(this, name, body)
|
190
194
|
run: (callback) ->
|
191
195
|
throw "No root is defined" unless @root?
|
192
|
-
count = 0
|
193
196
|
testFile = this
|
194
197
|
testStates = {}
|
195
|
-
nextTest = ->
|
196
|
-
testFile.tests[count]
|
197
|
-
|
198
|
-
|
198
|
+
nextTest = (count) ->
|
199
|
+
test = testFile.tests[count]
|
200
|
+
before.call(test) for before in testFile.befores
|
201
|
+
try
|
199
202
|
if count < testFile.tests.length
|
200
|
-
|
203
|
+
test.run (state) ->
|
204
|
+
testStates[test.name] = state
|
205
|
+
nextTest(count + 1)
|
201
206
|
else
|
202
207
|
testFile.report(testStates)
|
203
208
|
callback()
|
204
|
-
|
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
|
+
nextTest(0)
|
205
216
|
report: (testStates) ->
|
206
217
|
success = 0
|
207
218
|
failure = 0
|
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Hull
|