visionmedia-jspec 2.3.0 → 2.3.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/History.rdoc CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ === 2.3.1 / 2009-06-25
3
+
4
+ * Fixed; all stubs generated with stub() are restored
5
+ to their original methods after each 'it' block. See
6
+ README for details.
7
+
2
8
  === 2.3.0 / 2009-06-25
3
9
 
4
10
  * Added stub()
data/README.rdoc CHANGED
@@ -209,6 +209,14 @@ JSpec currently provides very simple stubbing support shown below:
209
209
 
210
210
  person = { toString : function(){ return '<Person>' } }
211
211
  stub(person, 'toString').and_return('Ive been stubbed!')
212
+
213
+ After each spec all stubs are restored to their original methods so
214
+ there is no reason to explicitly call destub(). To persist stubs,
215
+ use a before_each hook:
216
+
217
+ before_each
218
+ stub(someObject, 'method').and_return({ some : thing })
219
+ end
212
220
 
213
221
  To destub a method simply call destub() at any time:
214
222
 
data/bin/jspec CHANGED
@@ -10,7 +10,7 @@ require 'fileutils'
10
10
  RHINO = 'java org.mozilla.javascript.tools.shell.Main'
11
11
 
12
12
  program :name, 'JSpec'
13
- program :version, '2.3.0'
13
+ program :version, '2.3.1'
14
14
  program :description, 'JavaScript BDD Testing Framework'
15
15
  default_command :bind
16
16
 
data/jspec.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{jspec}
5
- s.version = "2.3.0"
5
+ s.version = "2.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
data/lib/jspec.js CHANGED
@@ -5,10 +5,11 @@
5
5
 
6
6
  JSpec = {
7
7
 
8
- version : '2.3.0',
8
+ version : '2.3.1',
9
9
  suites : [],
10
10
  allSuites : [],
11
11
  matchers : {},
12
+ stubbed : [],
12
13
  stats : { specs : 0, assertions : 0, failures : 0, passes : 0, specsFinished : 0, suitesFinished : 0 },
13
14
  options : { profile : false },
14
15
 
@@ -899,7 +900,9 @@
899
900
 
900
901
  /**
901
902
  * Destub _object_'s _method_. When no _method_ is passed
902
- * all stubbed methods are destubbed.
903
+ * all stubbed methods are destubbed. When no arguments
904
+ * are passed every object found in JSpec.stubbed will be
905
+ * destubbed.
903
906
  *
904
907
  * @param {mixed} object
905
908
  * @param {string} method
@@ -915,14 +918,19 @@
915
918
  delete object['__prototype__' + method]
916
919
  delete object['__original____' + method]
917
920
  }
918
- else
921
+ else if (object) {
919
922
  for (var key in object)
920
923
  if (captures = key.match(/^(?:__prototype__|__original__)(.*)/))
921
924
  destub(object, captures[1])
925
+ }
926
+ else
927
+ while (JSpec.stubbed.length)
928
+ destub(JSpec.stubbed.shift())
922
929
  },
923
930
 
924
931
  /**
925
- * Stub _object_'s _method_. Example:
932
+ * Stub _object_'s _method_.
933
+ *
926
934
  * stub(foo, 'toString').and_return('bar')
927
935
  *
928
936
  * @param {mixed} object
@@ -934,13 +942,14 @@
934
942
  stub : function(object, method) {
935
943
  return {
936
944
  and_return : function(result) {
945
+ JSpec.stubbed.push(object)
937
946
  var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__'
938
947
  object[type + method] = object[method]
939
948
  object[method] = function(){ return result }
940
949
  }
941
950
  }
942
951
  },
943
-
952
+
944
953
  /**
945
954
  * Map callback return values.
946
955
  *
@@ -1179,6 +1188,7 @@
1179
1188
  catch (e) { fail(e) }
1180
1189
  spec.runDeferredAssertions()
1181
1190
  if (option('profile')) console.timeEnd(spec.description)
1191
+ destub()
1182
1192
  this.stats.specsFinished++
1183
1193
  this.stats.assertions += spec.assertions.length
1184
1194
  },
data/spec/spec.utils.js CHANGED
@@ -29,11 +29,30 @@ describe 'Utility'
29
29
  object.stubby().should.eql 'Oh no im new'
30
30
  end
31
31
 
32
- it 'should with a single argument should destub all methods stubbed related to the object passed'
32
+ it 'should destub all methods stubbed related to the object passed when no method is given'
33
33
  destub(object)
34
34
  object.toString().should.eql '<Im an object>'
35
35
  object.stubby().should.eql 'Not stubbed'
36
36
  end
37
+
38
+ describe 'should restore after each spec'
39
+ before
40
+ a = { toString : function(){ return 'Wahoo' }}
41
+ b = { toString : function(){ return 'Wahhhhhooo' }}
42
+ end
43
+
44
+ it 'should stub'
45
+ stub(a, 'toString').and_return('Oh no')
46
+ stub(b, 'toString').and_return('Oh noooo')
47
+ a.toString().should.eql 'Oh no'
48
+ b.toString().should.eql 'Oh noooo'
49
+ end
50
+
51
+ it 'should restore'
52
+ a.toString().should.eql 'Wahoo'
53
+ b.toString().should.eql 'Wahhhhhooo'
54
+ end
55
+ end
37
56
  end
38
57
  end
39
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionmedia-jspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk