ghostbuster 0.2.0 → 0.2.1

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 CHANGED
@@ -10,7 +10,7 @@ To install first `gem install ghostbuster`. Once you've done that, you can run `
10
10
 
11
11
  Once installed, you can simply use `ghostbuster [path/to/Ghostfile]` to run your tests.
12
12
 
13
- ## `Ghostfile`
13
+ ## Ghostfile
14
14
 
15
15
  Your `Ghostfile` handles your configuration. To set the pattern use:
16
16
 
@@ -21,7 +21,7 @@ Your `Ghostfile` handles your configuration. To set the pattern use:
21
21
  To enable (or disable) screenshots use:
22
22
 
23
23
  ~~~~
24
- ghost.take_screenshots! # or #do_not_takescreenshots! defaults to take_screenshots!
24
+ ghost.take_screenshots! # or #do_not_takescreenshots! defaults to take_screenshots!
25
25
  ~~~~
26
26
 
27
27
  To set the directory your screenshots will save to use:
@@ -36,6 +36,20 @@ To set the dimensions for the screenshots use:
36
36
  ghost.screenshot_dimensions 800, 2000 # x, y
37
37
  ~~~~
38
38
 
39
+ To set the command for starting your server use:
40
+
41
+ ~~~~
42
+ ghost.start_command "./start.sh"
43
+ ~~~~
44
+
45
+ To set the command for stopping your server use:
46
+
47
+ ~~~~
48
+ ghost.stop_command "./stop.sh"
49
+ ~~~~
50
+
51
+
52
+
39
53
  If no Ghostfile is found, it will simply use the defaults.
40
54
 
41
55
  You should get some output that looks something like this.
@@ -33,4 +33,8 @@ phantom.test.add "Before block var", ->
33
33
  @succeed()
34
34
 
35
35
  phantom.test.add "This test will explode!", ->
36
- throw "I hate you!"
36
+ throw "I hate you!"
37
+
38
+ phantom.test.add "This test has no succeed", ->
39
+ @get '/form', ->
40
+ "so, like, this test sucks"
@@ -1,7 +1,6 @@
1
1
  class Ghostbuster
2
2
  class Config
3
-
4
- attr_accessor :pattern, :screenshot_dir
3
+ attr_accessor :pattern, :screenshot_dir, :start_command, :stop_command
5
4
  attr_reader :screenshot_x, :screenshot_y
6
5
  def initialize(path_to_file = nil)
7
6
  @config_file = path_to_file || './Ghostfile'
@@ -9,6 +8,7 @@ class Ghostbuster
9
8
  @pattern = "./test_*.coffee"
10
9
  @screenshot_dir = "."
11
10
  @screenshots = true
11
+ @start_command, @stop_command = "./start.sh", "./stop.sh"
12
12
  if File.exist?(@config_file)
13
13
  instance_eval File.read(@config_file), @config_file, 1
14
14
  end
@@ -1,3 +1,3 @@
1
1
  class Ghostbuster
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -16,7 +16,9 @@ class Test
16
16
  setLastError: (error) ->
17
17
  @runner.lastErrors[@name] = error
18
18
  waitForAssertions: (whenDone) ->
19
+ @stopTestTimer()
19
20
  if @assertions.length == 0
21
+ @startTestTimer()
20
22
  whenDone.call(this)
21
23
  else
22
24
  test = this
@@ -25,7 +27,18 @@ class Test
25
27
  setTimeout waiting, 10
26
28
  actuallyRun: -> true
27
29
  run: (callback) ->
30
+ @startTestTimer()
28
31
  @runWithFunction(@testBody, callback)
32
+ stopTestTimer: ->
33
+ if @testTimer?
34
+ clearTimeout @testTimer
35
+ @testTimer = null
36
+ startTestTimer: ->
37
+ test = this
38
+ @testTimer ||= setTimeout (->
39
+ test.setLastError("This test took too long")
40
+ test.fail()
41
+ ), 5000
29
42
  runWithFunction: (fn, @callback) ->
30
43
  fn.call(this)
31
44
  get: (path, getCallback) ->
@@ -43,8 +56,10 @@ class Test
43
56
  @page.open @runner.normalizePath(path), loadedCallback
44
57
  succeed: ->
45
58
  @waitForAssertions ->
59
+ @stopTestTimer()
46
60
  @callback(true)
47
61
  fail: (msg) ->
62
+ @stopTestTimer()
48
63
  @callback(false, msg)
49
64
  assert: (opts, valueFetcher) ->
50
65
  @assertions.push(new Assertion(this, ++@assertionIndex, opts, valueFetcher))
@@ -65,6 +80,7 @@ class Assertion
65
80
  failedCallback = ->
66
81
  assertion.start()
67
82
  if @count == 0
83
+ test.stopTestTimer()
68
84
  fatalCallback = ->
69
85
  test.fail(test.getLastError() || "This assertion failed to complete.")
70
86
  @fatal = setTimeout(fatalCallback, assertion.totalTime)
@@ -72,6 +88,7 @@ class Assertion
72
88
  assertion.count++
73
89
  if val == true
74
90
  test.resetLastError()
91
+ test.startTestTimer()
75
92
  test.assertions.splice(test.assertions.indexOf(assertion), 1)
76
93
  clearTimeout assertion.fatal
77
94
  if test.runner.useScreenshots()
@@ -229,6 +246,7 @@ class TestFile
229
246
  testStates[test.name] = state
230
247
  nextTest(count + 1)
231
248
  catch e
249
+ test.stopTestTimer()
232
250
  testFile.lastErrors[test.name] = e.toString()
233
251
  testStates[test.name] = false
234
252
  nextTest(count + 1)
data/lib/ghostbuster.rb CHANGED
@@ -21,14 +21,14 @@ class Ghostbuster
21
21
  status = 1
22
22
  Dir.chdir(@dir) do
23
23
  spinner "Starting server" do
24
- sh "./start.sh"
24
+ sh @config.start_command
25
25
  sleep 2
26
26
  end
27
27
  begin
28
28
  _, status = Process.waitpid2 fork { exec("#{@phantom_bin} #{@ghost_lib} #{@config.screenshots?} #{@config.screenshot_x} #{@config.screenshot_y} #{File.expand_path(@config.screenshot_dir)} #{Dir[@config.pattern].to_a.join(' ')}") }
29
29
  ensure
30
30
  spinner "Stopping server" do
31
- sh "./stop.sh"
31
+ sh @config.stop_command
32
32
  end
33
33
  end
34
34
  end
data/test/output CHANGED
@@ -18,6 +18,8 @@ For test_ghostmore.coffee
18
18
  ✓ Before block var
19
19
  ✗ This test will explode!
20
20
  I hate you!
21
+ ✗ This test has no succeed
22
+ This test took too long
21
23
 
22
- 7 success, 3 failure, 1 pending
24
+ 7 success, 4 failure, 1 pending
23
25
  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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Hull