screw_server 0.1.4
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/Gemfile.run +3 -0
- data/Gemfile.run.lock +41 -0
- data/assets/screw-jslint.js +69 -0
- data/assets/screw-server.js +120 -0
- data/assets/screw.css +70 -0
- data/assets/vendor/fulljslint.js +5699 -0
- data/assets/vendor/screw-unit/CHANGES +7 -0
- data/assets/vendor/screw-unit/EXAMPLE.html +68 -0
- data/assets/vendor/screw-unit/LICENSE +22 -0
- data/assets/vendor/screw-unit/README.markdown +307 -0
- data/assets/vendor/screw-unit/example/models/cat.js +5 -0
- data/assets/vendor/screw-unit/example/models/man.js +17 -0
- data/assets/vendor/screw-unit/example/spec/matchers/have.js +8 -0
- data/assets/vendor/screw-unit/example/spec/models/cat_spec.js +31 -0
- data/assets/vendor/screw-unit/example/spec/models/man_spec.js +34 -0
- data/assets/vendor/screw-unit/example/spec/spec_helper.js +5 -0
- data/assets/vendor/screw-unit/example/spec/suite.html +25 -0
- data/assets/vendor/screw-unit/lib/jquery-1.2.6.js +3549 -0
- data/assets/vendor/screw-unit/lib/jquery.fn.js +29 -0
- data/assets/vendor/screw-unit/lib/jquery.print.js +109 -0
- data/assets/vendor/screw-unit/lib/screw.behaviors.js +101 -0
- data/assets/vendor/screw-unit/lib/screw.builder.js +90 -0
- data/assets/vendor/screw-unit/lib/screw.css +90 -0
- data/assets/vendor/screw-unit/lib/screw.events.js +45 -0
- data/assets/vendor/screw-unit/lib/screw.matchers.js +203 -0
- data/assets/vendor/screw-unit/spec/behaviors_spec.js +188 -0
- data/assets/vendor/screw-unit/spec/matchers_spec.js +391 -0
- data/assets/vendor/screw-unit/spec/print_spec.js +158 -0
- data/assets/vendor/screw-unit/spec/spec_helper.js +0 -0
- data/assets/vendor/screw-unit/spec/suite.html +18 -0
- data/assets/vendor/smoke/LICENSE +22 -0
- data/assets/vendor/smoke/README.markdown +68 -0
- data/assets/vendor/smoke/lib/smoke.core.js +49 -0
- data/assets/vendor/smoke/lib/smoke.mock.js +219 -0
- data/assets/vendor/smoke/lib/smoke.stub.js +29 -0
- data/assets/vendor/smoke/plugins/screw.mocking.js +26 -0
- data/assets/vendor/smoke/spec/core_spec.js +115 -0
- data/assets/vendor/smoke/spec/mock_spec.js +431 -0
- data/assets/vendor/smoke/spec/screw_integration_spec.js +17 -0
- data/assets/vendor/smoke/spec/spec_helper.js +0 -0
- data/assets/vendor/smoke/spec/stub_spec.js +17 -0
- data/assets/vendor/smoke/spec/su/jquery-1.2.3.js +3408 -0
- data/assets/vendor/smoke/spec/su/jquery.fn.js +29 -0
- data/assets/vendor/smoke/spec/su/jquery.print.js +108 -0
- data/assets/vendor/smoke/spec/su/screw.behaviors.js +91 -0
- data/assets/vendor/smoke/spec/su/screw.builder.js +80 -0
- data/assets/vendor/smoke/spec/su/screw.css +74 -0
- data/assets/vendor/smoke/spec/su/screw.events.js +38 -0
- data/assets/vendor/smoke/spec/su/screw.matchers.js +65 -0
- data/assets/vendor/smoke/spec/suite.html +29 -0
- data/bin/screw_server +43 -0
- data/lib/screw_server/app.rb +197 -0
- data/lib/screw_server/base.rb +21 -0
- data/lib/screw_server/fixture_file.rb +17 -0
- data/lib/screw_server/jslint_suite.rb +51 -0
- data/lib/screw_server/spec_file.rb +76 -0
- data/lib/screw_server.rb +2 -0
- data/screw_server.gemspec +28 -0
- data/views/index.haml +13 -0
- data/views/missing_spec_helper.haml +12 -0
- data/views/no_specs.haml +11 -0
- data/views/run_spec.haml +30 -0
- data/views/sample_spec.js +7 -0
- data/views/sample_spec_helper.js +2 -0
- metadata +257 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("core", function() {
|
3
|
+
var anonymous_function = function() { return arguments };
|
4
|
+
describe("printArguments", function() {
|
5
|
+
it("should return '()' is the arguments are empty", function() {
|
6
|
+
expect(Smoke.printArguments(arguments)).to(equal, '()');
|
7
|
+
});
|
8
|
+
|
9
|
+
it("should return '()' is the arguments are undefined", function() {
|
10
|
+
expect(Smoke.printArguments()).to(equal, '()');
|
11
|
+
});
|
12
|
+
|
13
|
+
it("should return the arguments comma seperated wrapped in parenthesis", function() {
|
14
|
+
var args = anonymous_function(1,2);
|
15
|
+
expect(Smoke.printArguments(args)).to(equal, '(1, 2)');
|
16
|
+
});
|
17
|
+
|
18
|
+
it("should handle being passed something other than an array or arguments object", function() {
|
19
|
+
expect(Smoke.printArguments(false)).to(equal, '(false)');
|
20
|
+
});
|
21
|
+
});
|
22
|
+
|
23
|
+
describe("argumentsToArray", function() {
|
24
|
+
it("should return an array", function() {
|
25
|
+
expect(Smoke.argumentsToArray(anonymous_function(1,2)) instanceof Array).to(equal, true);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("should return the arguments in an array", function() {
|
29
|
+
expect(Smoke.argumentsToArray(anonymous_function(1,2))).to(equal, [1,2]);
|
30
|
+
});
|
31
|
+
});
|
32
|
+
|
33
|
+
describe("compare", function() {
|
34
|
+
describe("with arrays", function() {
|
35
|
+
var array = [1,2,3], nested_array = [[1,2], [3,4]];
|
36
|
+
it("should return true if the two arrays are equal", function() {
|
37
|
+
expect(Smoke.compare(array, [1,2,3])).to(equal, true);
|
38
|
+
});
|
39
|
+
|
40
|
+
it("should return true if the two nested arrays are equal", function() {
|
41
|
+
expect(Smoke.compare(nested_array, [[1,2], [3,4]])).to(equal, true);
|
42
|
+
});
|
43
|
+
|
44
|
+
it("should return false if the two arrays are not equal", function() {
|
45
|
+
expect(Smoke.compare(array, [1,2,3,4])).to(equal, false);
|
46
|
+
})
|
47
|
+
|
48
|
+
it("should return false if the two nested arrays are not equal", function() {
|
49
|
+
expect(Smoke.compare(nested_array, [[1,2],[3]])).to(equal, false);
|
50
|
+
})
|
51
|
+
});
|
52
|
+
|
53
|
+
describe("with objects", function() {
|
54
|
+
var object = { foo: 'bar' }, nested_object = { foo: { a: 'b' }, bar: { c: 'd'} };
|
55
|
+
it("should return true if the two objects are equal", function() {
|
56
|
+
expect(Smoke.compare(object, { foo: 'bar' })).to(equal, true);
|
57
|
+
});
|
58
|
+
|
59
|
+
it("should return true if the two nested objects are equal", function() {
|
60
|
+
expect(Smoke.compare(nested_object, { foo: { a: 'b' }, bar: { c: 'd'} })).to(equal, true);
|
61
|
+
});
|
62
|
+
|
63
|
+
it("should return false if the two objects are not equal", function() {
|
64
|
+
expect(Smoke.compare(object, {bar: 'foo'})).to(equal, false);
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should return false if the two nested objects are not equal", function() {
|
68
|
+
expect(Smoke.compare(nested_object, { foo: { c: 'd' }, bar: { a: 'b' } })).to(equal, false);
|
69
|
+
});
|
70
|
+
|
71
|
+
it("should return false if an one of the objects has an additional property", function() {
|
72
|
+
expect(Smoke.compare(object, { foo: 'bar', bar: 'foo' })).to(equal, false);
|
73
|
+
})
|
74
|
+
});
|
75
|
+
|
76
|
+
describe('with value types', function() {
|
77
|
+
var string = 'foo', number = 1;
|
78
|
+
it("should return true if the two strings are equal", function() {
|
79
|
+
expect(Smoke.compare(string, 'foo')).to(equal, true);
|
80
|
+
});
|
81
|
+
|
82
|
+
it("should return true if the two numbers are equal", function() {
|
83
|
+
expect(Smoke.compare(number, 1)).to(equal, true);
|
84
|
+
});
|
85
|
+
|
86
|
+
it("should return false if the two strings are not equal", function() {
|
87
|
+
expect(Smoke.compare(string, 'bar')).to(equal, false);
|
88
|
+
});
|
89
|
+
|
90
|
+
it("should return false if the two number are not equal", function() {
|
91
|
+
expect(Smoke.compare(number, 2)).to(equal, false);
|
92
|
+
});
|
93
|
+
})
|
94
|
+
|
95
|
+
describe("with mixed types", function() {
|
96
|
+
var array = [1, { foo: 'bar'}, '2'], object = { foo: [1,2,3], bar: 'foo', one: 1 };
|
97
|
+
it("should return true if the two arrays with mixed types are equal", function() {
|
98
|
+
expect(Smoke.compare(array, [1, { foo: 'bar'}, '2'])).to(equal, true);
|
99
|
+
});
|
100
|
+
|
101
|
+
it("should return false if the two arrays with mixed types are not equal", function() {
|
102
|
+
expect(Smoke.compare(array, [1, { foo: 'bar'}, 3])).to(equal, false);
|
103
|
+
});
|
104
|
+
|
105
|
+
it("should return true if the two objects with mixed types are equal", function() {
|
106
|
+
expect(Smoke.compare(object, { foo: [1,2,3], bar: 'foo', one: 1 })).to(equal, true);
|
107
|
+
});
|
108
|
+
|
109
|
+
it("should return false if the two objects with mixed types are not equal", function() {
|
110
|
+
expect(Smoke.compare(object, { foo: [1,2,3], bar: 'foo', two: 3 })).to(equal, false);
|
111
|
+
});
|
112
|
+
})
|
113
|
+
});
|
114
|
+
});
|
115
|
+
});
|
@@ -0,0 +1,431 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("mocking", function() {
|
3
|
+
describe("basics", function() {
|
4
|
+
it("allows stubbing directly on mock objects", function() {
|
5
|
+
mockObj = mock().stub('bar').and_return('baz');
|
6
|
+
expect(mockObj.bar()).to(equal, 'baz');
|
7
|
+
});
|
8
|
+
|
9
|
+
it("should check an exact call count", function() {
|
10
|
+
var m = mock()
|
11
|
+
m.should_receive('bar').exactly('twice');
|
12
|
+
m.bar();
|
13
|
+
m.bar();
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should check a never call count", function() {
|
17
|
+
var m = mock()
|
18
|
+
m.should_not_receive('bar');
|
19
|
+
});
|
20
|
+
|
21
|
+
it("should fail when an expectation is called at all", function() {
|
22
|
+
var m = mock()
|
23
|
+
m.should_not_receive('bar');
|
24
|
+
m.bar();
|
25
|
+
try {
|
26
|
+
Smoke.checkExpectations();
|
27
|
+
throw("exception");
|
28
|
+
} catch(e) {
|
29
|
+
Smoke.reset();
|
30
|
+
expect(e).to(equal, 'expected bar() to be called exactly 0 times but it got called 1 times');
|
31
|
+
}
|
32
|
+
});
|
33
|
+
|
34
|
+
it("should fail when an expectation is called too many times", function() {
|
35
|
+
var m = mock();
|
36
|
+
m.should_receive('bar').exactly('once');
|
37
|
+
m.bar();
|
38
|
+
m.bar();
|
39
|
+
try {
|
40
|
+
Smoke.checkExpectations();
|
41
|
+
throw("exception");
|
42
|
+
} catch(e) {
|
43
|
+
Smoke.reset();
|
44
|
+
expect(e).to(equal, 'expected bar() to be called exactly 1 times but it got called 2 times');
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
48
|
+
it("should fail when an expectation is set and not called", function() {
|
49
|
+
var m = mock();
|
50
|
+
m.should_receive('bar').exactly('once');
|
51
|
+
try {
|
52
|
+
Smoke.checkExpectations();
|
53
|
+
throw("exception");
|
54
|
+
} catch(e) {
|
55
|
+
Smoke.reset();
|
56
|
+
expect(e).to(equal, 'expected bar() to be called exactly 1 times but it got called 0 times');
|
57
|
+
}
|
58
|
+
});
|
59
|
+
|
60
|
+
it("should not check arguments when with_arguments is not used", function() {
|
61
|
+
var m = mock()
|
62
|
+
m.should_receive('bar').exactly('once');
|
63
|
+
m.bar(1);
|
64
|
+
});
|
65
|
+
|
66
|
+
it("should check a minimum call count", function() {
|
67
|
+
var m = mock()
|
68
|
+
m.should_receive('bar').at_least('once');
|
69
|
+
m.bar();
|
70
|
+
});
|
71
|
+
|
72
|
+
it("should check a minimum call count when defined via must_receive shortcut", function() {
|
73
|
+
var m = mock()
|
74
|
+
m.must_receive('bar');
|
75
|
+
m.bar();
|
76
|
+
});
|
77
|
+
|
78
|
+
it("should check a maximum call count", function() {
|
79
|
+
var m = mock()
|
80
|
+
m.should_receive('bar').at_most(2,'times');
|
81
|
+
m.bar();
|
82
|
+
m.bar();
|
83
|
+
});
|
84
|
+
|
85
|
+
it("should allow return values directly from mocks",function() {
|
86
|
+
var m = mock()
|
87
|
+
m.should_receive('bar').exactly('once').and_return('hello');
|
88
|
+
expect(m.bar()).to(equal, 'hello');
|
89
|
+
});
|
90
|
+
});
|
91
|
+
|
92
|
+
describe("with argument conditions", function() {
|
93
|
+
it("should only mock the exact method signature when with_arguments is used", function() {
|
94
|
+
mockObj = mock()
|
95
|
+
baz = {a:'a dummy obj'}
|
96
|
+
mockObj.should_receive('foo').with_arguments('bar',baz).and_return('foobar');
|
97
|
+
expect(mockObj.foo('bar',baz)).to(equal, 'foobar');
|
98
|
+
});
|
99
|
+
|
100
|
+
it("should throw an arguments mismatched error if the arguments aren't matched", function() {
|
101
|
+
mockObj = mock()
|
102
|
+
mockObj.should_receive('foo').with_arguments('bar').and_return('foobar');
|
103
|
+
try {
|
104
|
+
mockObj.foo('chicken');
|
105
|
+
} catch(e) {
|
106
|
+
expect(e).to(equal, 'expected foo with ("bar") but received it with ("chicken")')
|
107
|
+
}
|
108
|
+
});
|
109
|
+
it("should allow mocking multiple method signatures with different returns", function() {
|
110
|
+
mockObj = mock()
|
111
|
+
mockObj.should_receive('foo').with_arguments('bar').and_return('foobar');
|
112
|
+
mockObj.should_receive('foo').with_arguments('mouse').and_return('cheese');
|
113
|
+
expect(mockObj.foo('mouse')).to(equal, 'cheese');
|
114
|
+
expect(mockObj.foo('bar')).to(equal, 'foobar');
|
115
|
+
});
|
116
|
+
it("should allow mocking a method signature with arguments and setting expectations", function() {
|
117
|
+
mockObj = mock()
|
118
|
+
mockObj.should_receive('foo').with_arguments('bar').exactly('once');
|
119
|
+
mockObj.foo('bar')
|
120
|
+
});
|
121
|
+
|
122
|
+
it("should accept any arguments when with_any_arguments is used", function() {
|
123
|
+
mockObj = mock()
|
124
|
+
mockObj.should_receive('foo').with_any_arguments().exactly('twice').and_return("bar");
|
125
|
+
expect(mockObj.foo()).to(equal, "bar");
|
126
|
+
expect(mockObj.foo("a", "lot", "of", "arguments")).to(equal, "bar");
|
127
|
+
});
|
128
|
+
});
|
129
|
+
|
130
|
+
describe("with function execution", function() {
|
131
|
+
it("should execute the function", function() {
|
132
|
+
mockObj = mock();
|
133
|
+
var was_called = false;
|
134
|
+
mockObj.should_receive('foo').and_execute(function() {
|
135
|
+
was_called = true;
|
136
|
+
})
|
137
|
+
mockObj.foo();
|
138
|
+
expect(was_called).to(equal, true);
|
139
|
+
});
|
140
|
+
|
141
|
+
it("should be possible to re-mock a function that was already mocked", function() {
|
142
|
+
mockObj = mock();
|
143
|
+
var was_called_1 = 0;
|
144
|
+
var was_called_2 = 0;
|
145
|
+
mockObj.should_receive('foo').and_execute(function() {
|
146
|
+
was_called_1+=1;
|
147
|
+
})
|
148
|
+
mockObj.should_receive('foo').and_execute(function() {
|
149
|
+
was_called_2+=1;
|
150
|
+
})
|
151
|
+
mockObj.foo();
|
152
|
+
mockObj.foo();
|
153
|
+
expect(was_called_1).to(equal, 0);
|
154
|
+
expect(was_called_2).to(equal, 2);
|
155
|
+
});
|
156
|
+
|
157
|
+
it("should enforce call counts", function() {
|
158
|
+
mockObj = mock();
|
159
|
+
var was_called = 0;
|
160
|
+
mockObj.should_receive('foo').and_execute(function() {
|
161
|
+
was_called += 1;
|
162
|
+
}).exactly("twice");
|
163
|
+
mockObj.foo();
|
164
|
+
mockObj.foo();
|
165
|
+
expect(was_called).to(equal, 2);
|
166
|
+
});
|
167
|
+
|
168
|
+
it("should pass arguments to the function", function() {
|
169
|
+
mockObj = mock();
|
170
|
+
var was_called_with = null;
|
171
|
+
mockObj.should_receive('foo').and_execute(function(arg1, arg2) {
|
172
|
+
was_called_with = arg1+" and "+arg2;
|
173
|
+
}).exactly("once");
|
174
|
+
mockObj.foo("spam", "eggs");
|
175
|
+
expect(was_called_with).to(equal, "spam and eggs");
|
176
|
+
});
|
177
|
+
|
178
|
+
it("should return the return value of the function", function() {
|
179
|
+
mockObj = mock();
|
180
|
+
mockObj.should_receive('foo').and_execute(function(arg1, arg2) {
|
181
|
+
return arg1+" and "+arg2;
|
182
|
+
}).exactly("once");
|
183
|
+
expect(mockObj.foo("spam", "eggs")).to(equal, "spam and eggs");
|
184
|
+
});
|
185
|
+
|
186
|
+
it("should allow expectations inside the function", function() {
|
187
|
+
mockObj = mock();
|
188
|
+
mockObj.should_receive('foo').and_execute(function(arg1, arg2) {
|
189
|
+
expect(arg1+" and "+arg2).to(equal, "spam and eggs");
|
190
|
+
}).exactly("once");
|
191
|
+
mockObj.foo("spam", "eggs");
|
192
|
+
});
|
193
|
+
});
|
194
|
+
|
195
|
+
describe("with exception throwing", function() {
|
196
|
+
it("should throw the exception", function() {
|
197
|
+
mockObj = mock();
|
198
|
+
mockObj.should_receive('foo').and_throw("my exception");
|
199
|
+
var thrown = false;
|
200
|
+
try {
|
201
|
+
mockObj.foo()
|
202
|
+
}
|
203
|
+
catch (e) {
|
204
|
+
thrown = true;
|
205
|
+
}
|
206
|
+
expect(thrown).to(equal, true);
|
207
|
+
});
|
208
|
+
});
|
209
|
+
|
210
|
+
describe("added ontop of an existing object", function() {
|
211
|
+
before(function() {
|
212
|
+
obj = { say: "hello", shout: function() { return this.say.toUpperCase(); } }
|
213
|
+
mockObj = mock(obj);
|
214
|
+
});
|
215
|
+
|
216
|
+
it("should leave original properties intact", function() {
|
217
|
+
expect(mockObj.say).to(equal,'hello');
|
218
|
+
});
|
219
|
+
|
220
|
+
it("should leave original functions intact", function() {
|
221
|
+
expect(mockObj.shout()).to(equal,'HELLO');
|
222
|
+
});
|
223
|
+
|
224
|
+
it("should add methods to allow stubbing and mocking on the objects properties", function() {
|
225
|
+
expect(mockObj.should_receive).to_not(equal,undefined);
|
226
|
+
expect(mockObj.stub).to_not(equal,undefined);
|
227
|
+
});
|
228
|
+
|
229
|
+
it("shouldn't break Arrays", function() {
|
230
|
+
mockObj = mock([0,1,2,3]);
|
231
|
+
expect(mockObj[2]).to(equal,2);
|
232
|
+
expect(mockObj.length).to(equal,4);
|
233
|
+
});
|
234
|
+
|
235
|
+
it("should place expectations on existing methods destructively", function() {
|
236
|
+
myMock = mock({ say: "hello", shout: function() { throw "FAIL!" } });
|
237
|
+
myMock.should_receive('shout').exactly('once');
|
238
|
+
myMock.shout();
|
239
|
+
});
|
240
|
+
});
|
241
|
+
|
242
|
+
describe("proper teardown of mocks on global variables", function(){
|
243
|
+
var SomeGlobal = { say: "hello", shout: function() { return this.say.toUpperCase(); } };
|
244
|
+
|
245
|
+
it("when mocked in one test...", function(){
|
246
|
+
mock(SomeGlobal).should_receive("shout").and_return("some string");
|
247
|
+
expect(SomeGlobal.shout()).to(equal, "some string");
|
248
|
+
});
|
249
|
+
|
250
|
+
it("should not affect a later test", function(){
|
251
|
+
expect(SomeGlobal.shout()).to(equal, "HELLO");
|
252
|
+
});
|
253
|
+
it("should restore existing methods even when mocking the same object twice", function() {
|
254
|
+
var my_object = { say: "hello", shout: function() { return this.say.toUpperCase(); } };
|
255
|
+
myMock = mock(my_object);
|
256
|
+
myMock.should_receive('shout').exactly('once').and_return("hi");
|
257
|
+
myMock2 = mock(my_object);
|
258
|
+
myMock2.should_receive('shout').exactly('once').and_return("ola");
|
259
|
+
expect(myMock.shout()).to(equal,'ola');
|
260
|
+
Smoke.reset();
|
261
|
+
expect(myMock.shout()).to(equal,'HELLO');
|
262
|
+
});
|
263
|
+
});
|
264
|
+
|
265
|
+
describe("reseting mocks", function(){
|
266
|
+
it("should remove all mocking data from an object", function(){
|
267
|
+
var obj = { say: "hello", shout: function() { return this.say.toUpperCase(); } };
|
268
|
+
mock(obj).should_receive("shout").and_return("some string");
|
269
|
+
|
270
|
+
expect(obj._valuesBeforeMocking).to_not(equal, null);
|
271
|
+
expect(obj._expectations).to_not(equal, null);
|
272
|
+
expect(obj.stub).to_not(equal, null);
|
273
|
+
expect(obj.should_receive).to_not(equal, null);
|
274
|
+
expect(obj._checkExpectations).to_not(equal, null);
|
275
|
+
expect(obj._resetMocks).to_not(equal, null);
|
276
|
+
|
277
|
+
obj._resetMocks();
|
278
|
+
Smoke.mocks = [];
|
279
|
+
|
280
|
+
expect(obj._valuesBeforeMocking).to(equal, null);
|
281
|
+
expect(obj._expectations).to(equal, null);
|
282
|
+
expect(obj.stub).to(equal, null);
|
283
|
+
expect(obj.should_receive).to(equal, null);
|
284
|
+
expect(obj._checkExpectations).to(equal, null);
|
285
|
+
expect(obj._resetMocks).to(equal, null);
|
286
|
+
});
|
287
|
+
|
288
|
+
it("should replace the original functionality to the object", function(){
|
289
|
+
var obj = { say: "hello", shout: function() { return this.say.toUpperCase(); } };
|
290
|
+
mock(obj).should_receive("shout").and_return("some string");
|
291
|
+
expect(obj.shout()).to(equal, "some string");
|
292
|
+
|
293
|
+
obj._resetMocks();
|
294
|
+
Smoke.mocks = [];
|
295
|
+
|
296
|
+
expect(obj.shout()).to(equal, "HELLO");
|
297
|
+
});
|
298
|
+
|
299
|
+
it("should also restore a stubbed properties", function() {
|
300
|
+
var obj = { say: "hello" };
|
301
|
+
mock(obj).stub("say").and_set_to("goodbye");
|
302
|
+
expect(obj.say).to(equal, "goodbye");
|
303
|
+
|
304
|
+
obj._resetMocks();
|
305
|
+
Smoke.mocks = [];
|
306
|
+
|
307
|
+
expect(obj.say).to(equal, "hello");
|
308
|
+
});
|
309
|
+
});
|
310
|
+
|
311
|
+
describe("anonymous functions", function() {
|
312
|
+
before(function() {
|
313
|
+
foo = function() { return 'bar' };
|
314
|
+
mockObj = mock_function(foo);
|
315
|
+
});
|
316
|
+
|
317
|
+
it("should leave the original intact", function() {
|
318
|
+
expect(foo()).to(equal,'bar');
|
319
|
+
});
|
320
|
+
|
321
|
+
it("should still execute the mock like the original", function() {
|
322
|
+
expect(mockObj()).to(equal,'bar');
|
323
|
+
});
|
324
|
+
|
325
|
+
it("should only execute the original once", function() {
|
326
|
+
var counter = 0;
|
327
|
+
mockFn = mock_function(function() {
|
328
|
+
counter += 1;
|
329
|
+
});
|
330
|
+
mockFn();
|
331
|
+
expect(counter).to(equal, 1);
|
332
|
+
});
|
333
|
+
|
334
|
+
it("should still execute the mock like the original with arguments", function() {
|
335
|
+
var a = function(x,y,z) { return x+y+z };
|
336
|
+
aMock = mock_function(a)
|
337
|
+
expect(aMock('a','b','c')).to(equal,'abc');
|
338
|
+
});
|
339
|
+
|
340
|
+
it("should allow expectations to be set as usual", function() {
|
341
|
+
mockObj.should_receive('baz').exactly('once').and_return(1);
|
342
|
+
mockObj.baz()
|
343
|
+
});
|
344
|
+
|
345
|
+
it("should allow expectations to be set on invocations of itself", function() {
|
346
|
+
mockObj.should_be_invoked();
|
347
|
+
mockObj();
|
348
|
+
});
|
349
|
+
|
350
|
+
it("should allow expectation rules to be set", function() {
|
351
|
+
mockObj.should_be_invoked().exactly('twice').with_arguments('a');
|
352
|
+
mockObj('a');
|
353
|
+
mockObj('a');
|
354
|
+
});
|
355
|
+
|
356
|
+
it("should check for at least one invokation when defined via must_be_invoked shortcut", function() {
|
357
|
+
mockObj.must_be_invoked();
|
358
|
+
mockObj();
|
359
|
+
mockObj();
|
360
|
+
});
|
361
|
+
|
362
|
+
it("should guard against invokations when defined via must_not_be_invoked shortcut", function() {
|
363
|
+
mockObj.should_not_be_invoked();
|
364
|
+
mockObj();
|
365
|
+
try {
|
366
|
+
Smoke.checkExpectations();
|
367
|
+
throw("exception");
|
368
|
+
} catch(e) {
|
369
|
+
Smoke.reset();
|
370
|
+
expect(e).to(equal, 'expected anonymous_function() to be called exactly 0 times but it got called 1 times');
|
371
|
+
}
|
372
|
+
});
|
373
|
+
|
374
|
+
it("should allow a return value to be set", function() {
|
375
|
+
mockObj.should_be_invoked().and_return('bar');
|
376
|
+
expect(mockObj('foo')).to(equal, 'bar');
|
377
|
+
});
|
378
|
+
|
379
|
+
it("should allow multiple return values to be set through the argument matchers", function() {
|
380
|
+
mockObj.should_be_invoked().with_arguments('foo').and_return('bar');
|
381
|
+
mockObj.should_be_invoked().with_arguments('bar').and_return('foo');
|
382
|
+
expect(mockObj('foo')).to(equal, 'bar');
|
383
|
+
expect(mockObj('bar')).to(equal, 'foo');
|
384
|
+
});
|
385
|
+
|
386
|
+
it("allows passing in a name for the function as a second argument to make error messages clearer", function() {
|
387
|
+
mock_function(foo, 'foo').should_be_invoked().exactly('once');
|
388
|
+
try {
|
389
|
+
Smoke.checkExpectations();
|
390
|
+
throw("exception");
|
391
|
+
} catch(e) {
|
392
|
+
Smoke.reset();
|
393
|
+
expect(e).to(equal, 'expected foo() to be called exactly 1 times but it got called 0 times');
|
394
|
+
}
|
395
|
+
});
|
396
|
+
});
|
397
|
+
|
398
|
+
describe("when array has been monkey-patched by js library not to be named here (grrr)", function() {
|
399
|
+
before(function() {
|
400
|
+
Array.prototype.remove = function() {
|
401
|
+
alert('I like monkeys!');
|
402
|
+
}
|
403
|
+
});
|
404
|
+
it("should not throw a type error when checking expectations", function() {
|
405
|
+
var m = mock()
|
406
|
+
m.should_receive('bar').at_least('once');
|
407
|
+
m.bar();
|
408
|
+
try {
|
409
|
+
Smoke.checkExpectations();
|
410
|
+
} catch(e) {
|
411
|
+
/* Make sure we clean up to not break the rest of the tests */
|
412
|
+
delete(Array.prototype.remove);
|
413
|
+
throw e;
|
414
|
+
}
|
415
|
+
});
|
416
|
+
after(function() {
|
417
|
+
delete(Array.prototype.remove);
|
418
|
+
});
|
419
|
+
});
|
420
|
+
|
421
|
+
describe("an objects prototype", function() {
|
422
|
+
it("should allow mocks to be carried through to individual objects", function() {
|
423
|
+
Aobj = function() {};
|
424
|
+
Aobj.prototype = { aFunction: function() {return 'prototype function'} };
|
425
|
+
mock(Aobj.prototype).should_receive('aFunction').exactly('twice');
|
426
|
+
(new Aobj()).aFunction();
|
427
|
+
(new Aobj()).aFunction();
|
428
|
+
});
|
429
|
+
});
|
430
|
+
});
|
431
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("integrating with Screw.Unit", function() {
|
3
|
+
before(function() {
|
4
|
+
foo = {bar: function(attribute){return 'hello'}, baz:'goodbye'};
|
5
|
+
});
|
6
|
+
|
7
|
+
it("should forward stub() calls to new Stub to allow stub().and_return()", function() {
|
8
|
+
var myStub = stub(foo,'baz')
|
9
|
+
expect(myStub.and_return).to_not(equal, undefined);
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should forward mock() calls to new mock object to allow mock().should_receive()", function() {
|
13
|
+
var myMock = mock(foo);
|
14
|
+
expect(myMock.should_receive).to_not(equal,undefined)
|
15
|
+
});
|
16
|
+
});
|
17
|
+
});
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Screw.Unit(function() {
|
2
|
+
describe("stubbing", function() {
|
3
|
+
before(function() {
|
4
|
+
foo = {bar: function(attribute){return 'hello'}, baz:'goodbye'};
|
5
|
+
});
|
6
|
+
|
7
|
+
it("should return the stubbed value of a property", function() {
|
8
|
+
stub(foo,'baz').and_set_to('baz');
|
9
|
+
expect(foo.baz).to(equal, 'baz');
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should return the stubbed value of a function", function() {
|
13
|
+
stub(foo,'bar').and_return('bar');
|
14
|
+
expect(foo.bar()).to(equal, 'bar');
|
15
|
+
});
|
16
|
+
});
|
17
|
+
});
|