ghostbuster 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -4
- data/ghost/Ghostfile +1 -1
- data/ghost/test_ghost.coffee +1 -0
- data/ghost/test_ghostmore.coffee +1 -1
- data/ghost/test_injs.js +8 -0
- data/ghost/test_withoutroot.js +3 -0
- data/lib/ghostbuster.coffee +37 -1
- data/lib/ghostbuster/config.rb +1 -1
- data/lib/ghostbuster/version.rb +1 -1
- data/test/output +6 -1
- metadata +5 -3
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Once installed, you can simply use `ghostbuster [path/to/Ghostfile]` to run your
|
|
14
14
|
|
15
15
|
### Rake
|
16
16
|
|
17
|
-
As well, you can install Ghostbuster to run as a rake task
|
17
|
+
As well, you can install Ghostbuster to run as a rake task. To do this, add this to your `Rakefile`:
|
18
18
|
|
19
19
|
~~~~
|
20
20
|
require 'ghostbuster/install_rake'
|
@@ -25,7 +25,7 @@ As well, you can install Ghostbuster to run as a rake task:
|
|
25
25
|
Your `Ghostfile` handles your configuration. To set the pattern use:
|
26
26
|
|
27
27
|
~~~~
|
28
|
-
ghost.pattern = "test_*.coffee" # this is the default
|
28
|
+
ghost.pattern = "test_*.{js,coffee}" # this is the default
|
29
29
|
~~~~
|
30
30
|
|
31
31
|
To enable (or disable) screenshots use:
|
@@ -84,7 +84,7 @@ You should get some output that looks something like this.
|
|
84
84
|
|
85
85
|
For /Users/joshbuddy/Development/ghostbuster/ghost/test_ghostmore.coffee
|
86
86
|
✓ Simple form
|
87
|
-
|
87
|
+
◐ Form should do more things
|
88
88
|
|
89
89
|
~~~~
|
90
90
|
|
@@ -96,6 +96,8 @@ Your test directory should look something like this:
|
|
96
96
|
|
97
97
|
Look inside `ghost` to see some examples of what actual tests would look like. Let's dive into a couple of simple examples.
|
98
98
|
|
99
|
+
Here is one in Coffeescript.
|
100
|
+
|
99
101
|
~~~~
|
100
102
|
|
101
103
|
phantom.test.root = "http://127.0.0.1:4567" # you must specify your root.
|
@@ -110,7 +112,22 @@ Look inside `ghost` to see some examples of what actual tests would look like. L
|
|
110
112
|
|
111
113
|
~~~~
|
112
114
|
|
113
|
-
|
115
|
+
Here is the same test in Javascript.
|
116
|
+
|
117
|
+
~~~~
|
118
|
+
|
119
|
+
phantom.test.root = "http://127.0.0.1:4567"; // you must specify your root.
|
120
|
+
|
121
|
+
phantom.test.add("Simple index", function() { // this adds a test
|
122
|
+
this.get('/', function() { // this will get your a path relative to your root
|
123
|
+
// this asserts the first paragraph's inner text
|
124
|
+
this.body.assertFirst('p', function(p) { return p.innerHTML == 'This is my paragraph'});
|
125
|
+
// this asserts all li's have the test, List item {num}
|
126
|
+
this.body.assertAll('ul li', function(li, idx) { return li.innerHTML == "List item "+(idx + 1)});
|
127
|
+
this.succeed();
|
128
|
+
});
|
129
|
+
});
|
130
|
+
~~~~
|
114
131
|
|
115
132
|
## Assertions
|
116
133
|
|
data/ghost/Ghostfile
CHANGED
data/ghost/test_ghost.coffee
CHANGED
data/ghost/test_ghostmore.coffee
CHANGED
data/ghost/test_injs.js
ADDED
data/lib/ghostbuster.coffee
CHANGED
@@ -127,6 +127,35 @@ class Body
|
|
127
127
|
"
|
128
128
|
@test.page.evaluate(fn)
|
129
129
|
|
130
|
+
assertCount: (selector, opts, assertionCallback) ->
|
131
|
+
unless assertionCallback?
|
132
|
+
assertionCallback = opts
|
133
|
+
opts = {}
|
134
|
+
test = @test
|
135
|
+
@test.assert opts, (withValue) ->
|
136
|
+
alerter = if test.getLastError()? then "" else "alert('Assert count for selector #{selector} did not meet expectations, last count is '+count);"
|
137
|
+
eval "
|
138
|
+
var evaluator = function() {
|
139
|
+
try {
|
140
|
+
var assertionCallback = #{assertionCallback.toString()};
|
141
|
+
var count = document.querySelector('#{selector}').length;
|
142
|
+
var ret = assertionCallback(count);
|
143
|
+
if (ret) {
|
144
|
+
return true;
|
145
|
+
} else {
|
146
|
+
#{alerter}
|
147
|
+
return false;
|
148
|
+
}
|
149
|
+
} catch(e) {
|
150
|
+
var err = 'Assert count for selector #{selector} encountered an unexpected error:'+e;
|
151
|
+
console.log(err);
|
152
|
+
alert(err);
|
153
|
+
return false;
|
154
|
+
}
|
155
|
+
};
|
156
|
+
"
|
157
|
+
withValue @page.evaluate(evaluator)
|
158
|
+
|
130
159
|
assertLocation: (path, opts) ->
|
131
160
|
opts ||= {}
|
132
161
|
test = @test
|
@@ -300,7 +329,14 @@ class TestSuite
|
|
300
329
|
testFile = suite.args[count]
|
301
330
|
phantom.test = new TestFile(suite, testFile)
|
302
331
|
if phantom.injectJs(testFile)
|
303
|
-
|
332
|
+
try
|
333
|
+
phantom.test.run ->
|
334
|
+
count++
|
335
|
+
runNextTest()
|
336
|
+
catch e
|
337
|
+
console.log "For \033[1m#{testFile}\033[0m"
|
338
|
+
console.log " \033[31m\u2717\033[0m #{e.toString()}"
|
339
|
+
suite.failure++
|
304
340
|
count++
|
305
341
|
runNextTest()
|
306
342
|
else
|
data/lib/ghostbuster/config.rb
CHANGED
@@ -5,7 +5,7 @@ class Ghostbuster
|
|
5
5
|
def initialize(path_to_file = nil)
|
6
6
|
@config_file = path_to_file || './Ghostfile'
|
7
7
|
@screenshot_x, @screenshot_y = 800, 2000
|
8
|
-
@pattern = "./test_*.coffee"
|
8
|
+
@pattern = "./test_*.{coffee,js}"
|
9
9
|
@phantom_bin = File.join(ENV['HOME'], '.ghostbuster', 'phantomjs')
|
10
10
|
@screenshot_dir = "."
|
11
11
|
@screenshots = true
|
data/lib/ghostbuster/version.rb
CHANGED
data/test/output
CHANGED
@@ -21,5 +21,10 @@ For [1mtest_ghostmore.coffee[0m
|
|
21
21
|
[31m✗[0m This test has no succeed
|
22
22
|
This test took too long
|
23
23
|
|
24
|
-
|
24
|
+
For [1mtest_injs.js[0m
|
25
|
+
[32m✓[0m Test for 3 li's
|
26
|
+
|
27
|
+
For [1mtest_withoutroot.js[0m
|
28
|
+
[31m✗[0m No root is defined
|
29
|
+
8 success, 5 failure, 1 pending
|
25
30
|
Stopping server
|
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: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Hull
|
@@ -103,6 +103,8 @@ files:
|
|
103
103
|
- ghost/stop.sh
|
104
104
|
- ghost/test_ghost.coffee
|
105
105
|
- ghost/test_ghostmore.coffee
|
106
|
+
- ghost/test_injs.js
|
107
|
+
- ghost/test_withoutroot.js
|
106
108
|
- ghost/views/form.erb
|
107
109
|
- ghost/views/index.erb
|
108
110
|
- ghost/views/slow.erb
|