gusto 1.0.0.beta11 → 1.0.0.beta12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de263843ab3b190ea1a2d0ef8266b0b7d4e85073
4
- data.tar.gz: 596d9a3cb5595adb0ddbf16080bf3d2e8dc4514a
3
+ metadata.gz: 2f4d920e872884a37580166a39e194890f412ea4
4
+ data.tar.gz: 63557788ec1dbf8881303ba618a33c343c64ad26
5
5
  SHA512:
6
- metadata.gz: bdf0f74553ebe3a947cf8cb35ed1c45f8c30f99f5d41cce8c44f1113485c507f1ed24653e307af321a1dcf635187dd24f19e6373550dd2286673d275f1851ece
7
- data.tar.gz: e169d8ff132e7fa2ae1f2fbea7e259e544780e4776d6c7bfb8eaccc357b93ada9a4c8c14ea1b05a52ebd40b73d0f69e06b77d7d3760a63d2a2ae82b378a9158a
6
+ metadata.gz: 8a4f789b06d7cd4b905c923e32ae4ea2c84bd7e0b97e0700f1a14ad20055928cafeb7f47048d7fd24ff066d503bce21fef85939a26df3b1bc2b54ce96d7d8eef
7
+ data.tar.gz: 207fe7eff5dd1b2d3fdda6fed3adecde97118971032d90b7fd6f3b573d298fa501d345c83782ed518814e9b0c432d1a9899b7338f37122721b3928ca9a8477a3
data/lib/Spec/DSL.coffee CHANGED
@@ -9,14 +9,28 @@ window.Spec.DSL = DSL =
9
9
  before: (action) ->
10
10
  @__spec_definingSuite.filter null, action
11
11
 
12
- # Allows an assertion on a non-object value
12
+ # Sets up an expected result for this test
13
13
  expect: (object) ->
14
+ # Specifies that the object should receive a positive response from a
15
+ # matcher function
14
16
  to: (matcher) ->
15
- result = matcher(object)
16
- throw new Spec.ExpectationError("expected #{result[1]}") unless result[0]
17
+ match = matcher(object)
18
+ throw new Spec.ExpectationError("expected #{match.description}") unless match.result
19
+
20
+ # Specifies that the object should receive a negative response
17
21
  notTo: (matcher) ->
18
- result = matcher(object)
19
- throw new Spec.ExpectationError("expected not #{result[1]}") if result[0]
22
+ match = matcher(object)
23
+ throw new Spec.ExpectationError("expected not #{match.description}") if match.result
24
+
25
+ # Sets up a stub on the given method, with a delayed expectation that this
26
+ # stub method be called
27
+ toReceive: (method) ->
28
+ Spec.MethodStub.stub(object, method).expect()
29
+
30
+ # Sets up a stub on the given method, with a delayed expectation that this
31
+ # stub method is never called
32
+ notToReceive: (method) ->
33
+ Spec.MethodStub.stub(object, method).expect().never()
20
34
 
21
35
  # Syntactic sugar to create a before method that prepares a variable
22
36
  #
@@ -14,7 +14,7 @@ class window.Spec.DelayedExpectation
14
14
 
15
15
  @assert: ->
16
16
  asserting = @expectations
17
- @expectations = []
17
+ @reset()
18
18
  for expectation in asserting
19
19
  expectation.assert()
20
20
 
@@ -25,6 +25,11 @@ class window.Spec.DelayedExpectation
25
25
  @met = 0
26
26
  @desired = 1
27
27
 
28
+ # Specifies that this expectation should not be met
29
+ never: ->
30
+ @desired = 0
31
+ this
32
+
28
33
  # Specifies that this expectation must be met twice to count
29
34
  # as a success.
30
35
  twice: ->
@@ -4,23 +4,25 @@ window.Spec.Matchers =
4
4
  # Tests if matched value === expected value
5
5
  be: (expected) ->
6
6
  (value) ->
7
- [value is expected, "to be #{Spec.Util.inspect expected}, actual #{Spec.Util.inspect value}"]
7
+ result: value is expected
8
+ description: "be #{Spec.Util.inspect expected}, actual #{Spec.Util.inspect value}"
8
9
 
9
10
  # Tests that value type matches specified class
10
11
  beA: (klass) ->
11
12
  switch klass
12
- when Boolean then _haveType 'boolean'
13
- when Function then _haveType 'function'
14
- when Number then _haveType 'number'
15
- when String then _haveType 'string'
16
- when Object then _haveType 'object'
13
+ when Boolean then _haveType 'boolean', klass
14
+ when Function then _haveType 'function', klass
15
+ when Number then _haveType 'number', klass
16
+ when String then _haveType 'string', klass
17
+ when Object then _haveType 'object', klass
17
18
  else _beAnInstanceOf klass
18
19
 
19
20
  # Tests if matched value == expected value
20
21
  equal: (expected) ->
21
22
  (value) ->
22
- [String(value) == String(expected), "“#{String value}” to equal “#{String expected}” – #{$.trim diffString(String(value), String(expected))}"]
23
-
23
+ result: String(value) == String(expected)
24
+ description: "equal “#{String expected}”, actual “#{String value}” – #{$.trim diffString(String(value), String(expected))}"
25
+
24
26
  # All-purpose inclusion matcher
25
27
  include: (expected) ->
26
28
  if expected instanceof Array
@@ -28,7 +30,8 @@ window.Spec.Matchers =
28
30
  match = true
29
31
  for test in expected
30
32
  match = false unless (value.indexOf && value.indexOf(test) >= 0) || value[test]?
31
- [match, "to include #{Spec.Util.inspect expected}, actual #{Spec.Util.inspect value}"]
33
+ result: match
34
+ description: "include #{Spec.Util.inspect expected}, actual #{Spec.Util.inspect value}"
32
35
  else if typeof expected == 'object'
33
36
  (value) ->
34
37
  missing = {}
@@ -38,10 +41,11 @@ window.Spec.Matchers =
38
41
  unless value[test] isnt undefined && String(value[test]) == String(expected[test])
39
42
  match = false
40
43
  missing[test] = expected[test]
41
- [match, "to include #{Spec.Util.inspect expected}, actual #{Spec.Util.inspect value}, missing #{Spec.Util.inspect missing}"]
44
+ result: match
45
+ description: "include #{Spec.Util.inspect expected}, actual #{Spec.Util.inspect value}, missing #{Spec.Util.inspect missing}"
42
46
  else
43
47
  include([expected])
44
-
48
+
45
49
  # Tests if a function causes an error to be thrown when called
46
50
  throwError: (message) ->
47
51
  (fn) ->
@@ -50,20 +54,26 @@ window.Spec.Matchers =
50
54
  fn()
51
55
  catch e
52
56
  thrown = e.message
53
- finally
54
- if thrown
55
- return [thrown == message, "to throw an error with message “#{String thrown}”, actual message “#{String message}” – #{$.trim diffString(String(thrown), String(message))}"]
56
- else
57
- return [false, "to throw an error with message “#{message}”, no error thrown"]
57
+ if thrown
58
+ result: thrown == message
59
+ description: "throw an error with message “#{String thrown}”, actual message “#{String message}” – #{$.trim diffString(String(thrown), String(message))}"
60
+ else
61
+ result: false
62
+ description: "throw an error with message “#{message}”, no error thrown"
58
63
 
59
- # Tests a value type using typeof
60
- _haveType: (type) ->
61
- (value) ->
62
- [typeof value is type, "to have type “#{type}”, actual “#{typeof value}”"]
64
+ # Tests a value type using typeof, falling back to instanceof if type is an object
65
+ _haveType: (type, klass) ->
66
+ (value) =>
67
+ if typeof value is 'object'
68
+ @_beAnInstanceOf(klass)(value)
69
+ else
70
+ result: typeof value is type
71
+ description: "to have type “#{type}”, actual “#{typeof value}”"
63
72
 
64
73
  # Tests if matched value is an instance of class
65
74
  _beAnInstanceOf: (klass) ->
66
75
  (value) ->
67
- [value instanceof klass, "to be an instance of “#{klass}”"]
76
+ result: value instanceof klass
77
+ description: "#{value} to be an instance of “#{klass.name || klass}”, actually “#{Spec.Util.inspectClass value}"
68
78
 
69
79
  window.Spec.Matchers.beAn = window.Spec.Matchers.beA
@@ -31,6 +31,11 @@ class window.Spec.MethodStub.PossibleCall
31
31
  @expectation ||= Spec.DelayedExpectation.add('get called')
32
32
  this
33
33
 
34
+ # Delegates to expectation
35
+ never: ->
36
+ @expectation.never()
37
+ this
38
+
34
39
  # Delegates to expectation
35
40
  twice: ->
36
41
  @expectation.twice()
@@ -13,6 +13,13 @@ class window.Spec.MethodStub
13
13
  while stub = @stubs.pop()
14
14
  stub.remove()
15
15
 
16
+ @stub: (object, method) ->
17
+ stub = if object[method] && object[method]._stub
18
+ object[method]._stub
19
+ else
20
+ new Spec.MethodStub(object, method)
21
+ stub.possibleCall()
22
+
16
23
  constructor: (@object, @method) ->
17
24
  @possibleCalls = []
18
25
  @_replaceMethodOnObject()
@@ -3,11 +3,7 @@ window.Spec ||= {}
3
3
  window.Spec.ObjectDSL =
4
4
  # Stubs a method on object
5
5
  stub: (method) ->
6
- stub = if @[method] && @[method]._stub
7
- @[method]._stub
8
- else
9
- new Spec.MethodStub(this, method)
10
- stub.possibleCall()
6
+ Spec.MethodStub.stub(this, method)
11
7
 
12
8
  # Tests for a positive match
13
9
  should: (matcher) ->
@@ -19,8 +15,8 @@ window.Spec.ObjectDSL =
19
15
 
20
16
  # Creates a stub method with an expectation
21
17
  shouldReceive: (method) ->
22
- @stub(method).expect()
18
+ expect(this).toReceive method
23
19
 
24
20
  # Creates a stub method, with an expectation of no calls
25
- shouldNotReceive: (name) ->
26
- @shouldReceive(name).exactly(0).times
21
+ shouldNotReceive: (method) ->
22
+ expect(this).notToReceive method
data/lib/Spec/Util.coffee CHANGED
@@ -1,15 +1,14 @@
1
1
  window.Spec ||= {}
2
2
 
3
3
  window.Spec.Util =
4
+ # Extends one object with all properties from one or more other objects.
5
+ # This differs from extend methods in frameworks like jQuery and Underscore
6
+ # in that it will not overwrite properties that already exist
4
7
  extend: (object, extensions...) ->
5
8
  for extension in extensions
6
9
  for key, value of extension
7
- object[key] = value
8
-
9
- unextend: (object, extensions...) ->
10
- for extension in extensions
11
- for key, value of extension
12
- delete object[key]
10
+ object[key] ||= value
11
+ object
13
12
 
14
13
  reference: (value) ->
15
14
  if typeof value is 'function'
@@ -47,17 +46,7 @@ window.Spec.Util =
47
46
 
48
47
  # Returns an HTML representation of any kind of object
49
48
  inspect: (object) ->
50
- if object instanceof Array
51
- s = '['
52
- first = true
53
- for item in object
54
- if first
55
- first = false
56
- else
57
- first += ', '
58
- s += "“#{@escape(String(item))}”"
59
- s + ']'
60
- else if object is null
49
+ if object is null
61
50
  'null'
62
51
  else if object is undefined
63
52
  'undefined'
@@ -65,21 +54,24 @@ window.Spec.Util =
65
54
  'true'
66
55
  else if object is false
67
56
  'false'
57
+ else if object instanceof Array
58
+ items = for item in object
59
+ Spec.Util.inspect item
60
+ "[#{items.join ', '}]"
68
61
  else if typeof object == 'object'
69
- s = "{"
70
- first = true
71
- for key of object
62
+ properties = []
63
+ for key, value of object
72
64
  # Access hasOwnProperty through Object.prototype to work around bug
73
65
  # in IE6/7/8 when calling hasOwnProperty on a DOM element
74
66
  if Object.prototype.hasOwnProperty.call(object, key)
75
- if first
76
- first = false
77
- else
78
- s += ", "
79
- s += @escape(key) + ': “' + @escape(String(object[key])) + '”'
80
- s + "}"
67
+ properties.push Spec.Util.escape(key) + ': ' + Spec.Util.inspect(value)
68
+ "{#{properties.join ', '}}"
81
69
  else
82
- "“#{@escape(object)}”"
70
+ "“#{Spec.Util.escape(object)}”"
71
+
72
+ # Gets the class name of an object using JavaScript magic
73
+ inspectClass: (object) ->
74
+ Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1]
83
75
 
84
76
  # Escapes text for HTML
85
77
  escape: (string) ->
data/lib/Spec.coffee CHANGED
@@ -52,7 +52,6 @@ Spec.Util.extend window.Spec,
52
52
  Number,
53
53
  RegExp,
54
54
  String,
55
- @root,
56
55
  Element,
57
56
  jQuery,
58
57
  Spec.Mock
data/lib/gusto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gusto
2
- VERSION = "1.0.0.beta11"
2
+ VERSION = "1.0.0.beta12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gusto
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta11
4
+ version: 1.0.0.beta12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Cohen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-script
@@ -130,36 +130,36 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
- - assets/test_results.sass
134
133
  - assets/colors.sass
135
- - assets/spec.css.sass
136
134
  - assets/result_summary.sass
135
+ - assets/spec.css.sass
136
+ - assets/test_results.sass
137
137
  - bin/gusto
138
- - lib/Spec.coffee
139
- - lib/gusto.rb
140
138
  - lib/HtmlReport.coffee
141
- - lib/gusto/sprockets.rb
142
- - lib/gusto/configuration.rb
143
- - lib/gusto/version.rb
144
- - lib/gusto/server.rb
145
- - lib/gusto/cli_renderer.rb
146
- - lib/gusto/runner.rb
139
+ - lib/Spec.coffee
140
+ - lib/Spec/DSL.coffee
141
+ - lib/Spec/DelayedExpectation.coffee
147
142
  - lib/Spec/Matchers.coffee
148
- - lib/Spec/Mock.coffee
149
- - lib/Spec/MethodStub/PossibleCall.coffee
150
143
  - lib/Spec/MethodStub.coffee
144
+ - lib/Spec/MethodStub/PossibleCall.coffee
145
+ - lib/Spec/Mock.coffee
151
146
  - lib/Spec/ObjectDSL.coffee
152
- - lib/Spec/DSL.coffee
153
147
  - lib/Spec/Report.coffee
154
- - lib/Spec/Test.coffee
155
148
  - lib/Spec/RootSuite.coffee
156
- - lib/Spec/Util.coffee
157
149
  - lib/Spec/Suite.coffee
158
- - lib/Spec/DelayedExpectation.coffee
150
+ - lib/Spec/Test.coffee
151
+ - lib/Spec/Util.coffee
152
+ - lib/gusto.rb
153
+ - lib/gusto/cli_renderer.rb
154
+ - lib/gusto/configuration.rb
155
+ - lib/gusto/runner.rb
156
+ - lib/gusto/server.rb
157
+ - lib/gusto/sprockets.rb
158
+ - lib/gusto/version.rb
159
159
  - phantom/headless_runner.js
160
- - public/jsdiff.js
161
160
  - public/ie.js
162
161
  - public/jquery-1.10.2.js
162
+ - public/jsdiff.js
163
163
  - public/stacktrace.js
164
164
  - views/index.slim
165
165
  homepage: https://github.com/tobico/gusto
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: 1.3.1
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.0.3
185
+ rubygems_version: 2.2.0
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Coffeescript testing framework