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 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
- Form should do more things
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
- To use this within rake, just put `require 'ghostbuster/install_rake'` in your Rakefile.
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
 
@@ -1,4 +1,4 @@
1
- ghost.pattern = "test_*.coffee"
1
+ ghost.pattern = "test_*.{coffee,js}"
2
2
  ghost.do_not_take_screenshots! # or do_not_takescreenshots! defaults to true
3
3
  ghost.screenshot_dir = '.'
4
4
  ghost.screenshot_dimensions 800, 2000
@@ -35,3 +35,4 @@ phantom.test.add "Form input not equal", ->
35
35
  @body.assertFirst '#out', (out) ->
36
36
  out.innerHTML == 'this is NOT my input'
37
37
  @succeed()
38
+
@@ -37,4 +37,4 @@ phantom.test.add "This test will explode!", ->
37
37
 
38
38
  phantom.test.add "This test has no succeed", ->
39
39
  @get '/form', ->
40
- "so, like, this test sucks"
40
+ "so, like, this test sucks"
@@ -0,0 +1,8 @@
1
+ phantom.test.root = "http://127.0.0.1:4567"
2
+
3
+ phantom.test.add("Test for 3 li's", function() {
4
+ this.get('/', function() {
5
+ this.body.assertCount('li', function(count) { return count == 3})
6
+ })
7
+ this.succeed();
8
+ });
@@ -0,0 +1,3 @@
1
+ phantom.test.add("This is full of fail", function() {
2
+ this.succeed();
3
+ });
@@ -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
- phantom.test.run ->
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  class Ghostbuster
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -21,5 +21,10 @@ For test_ghostmore.coffee
21
21
  ✗ This test has no succeed
22
22
  This test took too long
23
23
 
24
- 7 success, 4 failure, 1 pending
24
+ For test_injs.js
25
+ ✓ Test for 3 li's
26
+
27
+ For test_withoutroot.js
28
+ ✗ 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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.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