screw_server 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Gemfile.run +3 -0
  2. data/Gemfile.run.lock +41 -0
  3. data/assets/screw-jslint.js +69 -0
  4. data/assets/screw-server.js +120 -0
  5. data/assets/screw.css +70 -0
  6. data/assets/vendor/fulljslint.js +5699 -0
  7. data/assets/vendor/screw-unit/CHANGES +7 -0
  8. data/assets/vendor/screw-unit/EXAMPLE.html +68 -0
  9. data/assets/vendor/screw-unit/LICENSE +22 -0
  10. data/assets/vendor/screw-unit/README.markdown +307 -0
  11. data/assets/vendor/screw-unit/example/models/cat.js +5 -0
  12. data/assets/vendor/screw-unit/example/models/man.js +17 -0
  13. data/assets/vendor/screw-unit/example/spec/matchers/have.js +8 -0
  14. data/assets/vendor/screw-unit/example/spec/models/cat_spec.js +31 -0
  15. data/assets/vendor/screw-unit/example/spec/models/man_spec.js +34 -0
  16. data/assets/vendor/screw-unit/example/spec/spec_helper.js +5 -0
  17. data/assets/vendor/screw-unit/example/spec/suite.html +25 -0
  18. data/assets/vendor/screw-unit/lib/jquery-1.2.6.js +3549 -0
  19. data/assets/vendor/screw-unit/lib/jquery.fn.js +29 -0
  20. data/assets/vendor/screw-unit/lib/jquery.print.js +109 -0
  21. data/assets/vendor/screw-unit/lib/screw.behaviors.js +101 -0
  22. data/assets/vendor/screw-unit/lib/screw.builder.js +90 -0
  23. data/assets/vendor/screw-unit/lib/screw.css +90 -0
  24. data/assets/vendor/screw-unit/lib/screw.events.js +45 -0
  25. data/assets/vendor/screw-unit/lib/screw.matchers.js +203 -0
  26. data/assets/vendor/screw-unit/spec/behaviors_spec.js +188 -0
  27. data/assets/vendor/screw-unit/spec/matchers_spec.js +391 -0
  28. data/assets/vendor/screw-unit/spec/print_spec.js +158 -0
  29. data/assets/vendor/screw-unit/spec/spec_helper.js +0 -0
  30. data/assets/vendor/screw-unit/spec/suite.html +18 -0
  31. data/assets/vendor/smoke/LICENSE +22 -0
  32. data/assets/vendor/smoke/README.markdown +68 -0
  33. data/assets/vendor/smoke/lib/smoke.core.js +49 -0
  34. data/assets/vendor/smoke/lib/smoke.mock.js +219 -0
  35. data/assets/vendor/smoke/lib/smoke.stub.js +29 -0
  36. data/assets/vendor/smoke/plugins/screw.mocking.js +26 -0
  37. data/assets/vendor/smoke/spec/core_spec.js +115 -0
  38. data/assets/vendor/smoke/spec/mock_spec.js +431 -0
  39. data/assets/vendor/smoke/spec/screw_integration_spec.js +17 -0
  40. data/assets/vendor/smoke/spec/spec_helper.js +0 -0
  41. data/assets/vendor/smoke/spec/stub_spec.js +17 -0
  42. data/assets/vendor/smoke/spec/su/jquery-1.2.3.js +3408 -0
  43. data/assets/vendor/smoke/spec/su/jquery.fn.js +29 -0
  44. data/assets/vendor/smoke/spec/su/jquery.print.js +108 -0
  45. data/assets/vendor/smoke/spec/su/screw.behaviors.js +91 -0
  46. data/assets/vendor/smoke/spec/su/screw.builder.js +80 -0
  47. data/assets/vendor/smoke/spec/su/screw.css +74 -0
  48. data/assets/vendor/smoke/spec/su/screw.events.js +38 -0
  49. data/assets/vendor/smoke/spec/su/screw.matchers.js +65 -0
  50. data/assets/vendor/smoke/spec/suite.html +29 -0
  51. data/bin/screw_server +43 -0
  52. data/lib/screw_server/app.rb +197 -0
  53. data/lib/screw_server/base.rb +21 -0
  54. data/lib/screw_server/fixture_file.rb +17 -0
  55. data/lib/screw_server/jslint_suite.rb +51 -0
  56. data/lib/screw_server/spec_file.rb +76 -0
  57. data/lib/screw_server.rb +2 -0
  58. data/screw_server.gemspec +28 -0
  59. data/views/index.haml +13 -0
  60. data/views/missing_spec_helper.haml +12 -0
  61. data/views/no_specs.haml +11 -0
  62. data/views/run_spec.haml +30 -0
  63. data/views/sample_spec.js +7 -0
  64. data/views/sample_spec_helper.js +2 -0
  65. metadata +257 -0
@@ -0,0 +1,158 @@
1
+ Screw.Unit(function() {
2
+ describe("Print", function() {
3
+ describe('when given undefined', function() {
4
+ it("returns 'undefined'", function() {
5
+ expect($.print(undefined)).to(equal, 'undefined');
6
+ });
7
+ });
8
+
9
+ describe('when given null', function() {
10
+ it("returns 'null'", function() {
11
+ expect($.print(null)).to(equal, 'null');
12
+ });
13
+ });
14
+
15
+ describe('when given a number', function() {
16
+ it("returns the string representation of the number", function() {
17
+ expect($.print(1)).to(equal, '1');
18
+ expect($.print(1.01)).to(equal, '1.01');
19
+ expect($.print(-1)).to(equal, '-1');
20
+ });
21
+ });
22
+
23
+ describe('when given a boolean', function() {
24
+ it("returns the string representation of the boolean", function() {
25
+ expect($.print(true)).to(equal, 'true');
26
+ expect($.print(false)).to(equal, 'false');
27
+ });
28
+ });
29
+
30
+ describe('when given a string', function() {
31
+ it("returns the string, quoted", function() {
32
+ expect($.print('asdf')).to(equal, '"asdf"');
33
+ });
34
+
35
+ describe('when the string is longer than the [max_string] option', function() {
36
+ it("returns the string, truncated", function() {
37
+ expect($.print('asdf', { max_string: 3 })).to(equal, '"asd..."');
38
+ });
39
+ });
40
+
41
+ describe('when the strings has quotes or escaped characters', function() {
42
+ it("returns the string, with quotes and escaped characters escaped", function() {
43
+ expect($.print('as"df')).to(equal, '"as\\"df"');
44
+ expect($.print('as\tdf')).to(equal, '"as\\tdf"');
45
+ });
46
+ });
47
+ });
48
+
49
+ describe('when given a function', function() {
50
+ it("returns the function's signature", function() {
51
+ expect($.print(function() {})).to(match, /function\s*\(\)/);
52
+ expect($.print(function foo() {})).to(match, /function\s*foo\(\)/);
53
+ expect($.print(function foo(bar) {})).to(match, /function\s*foo\(bar\)/);
54
+ });
55
+ });
56
+
57
+ describe('when given a RegExp', function() {
58
+ it('should print the regexp', function() {
59
+ expect($.print(/abc/i)).to(equal, '/abc/i');
60
+ });
61
+ });
62
+
63
+ describe('when given NaN', function() {
64
+ it('should print the string "NaN"', function() {
65
+ expect($.print(NaN)).to(equal, 'NaN');
66
+ });
67
+ });
68
+
69
+ describe('when given 0', function() {
70
+ it('should print the string "0"', function() {
71
+ expect($.print(0)).to(equal, '0');
72
+ });
73
+ });
74
+
75
+ describe('when given an element', function() {
76
+ it("returns the string representation of the element", function() {
77
+ expect($.print($('<div></div>').get(0))).to(equal, '<div>');
78
+ expect($.print($('<div foo="bar"></div>').get(0))).to(equal, '<div>');
79
+ expect($.print($('<div class="foo" id="bar"></div>').get(0))).to(equal, '<div class="foo" id="bar">');
80
+ });
81
+
82
+ describe('when the element is an img', function() {
83
+ it('prints out the img src attribute', function() {
84
+ expect($.print($('<img src="test.png"/>'))).to(match, /<img src=".*?test.png">/);
85
+ })
86
+ });
87
+ });
88
+
89
+ describe('when given an array', function() {
90
+ it("returns the printed elements, comma separated, encircled by square brackets", function() {
91
+ expect($.print([])).to(equal, '[]');
92
+ expect($.print([1])).to(equal, '[ 1 ]');
93
+ expect($.print([1, 2, 3])).to(equal, '[ 1, 2, 3 ]');
94
+ });
95
+
96
+ describe('when the array is longer than the [max_array] option', function() {
97
+ it("returns the printed array, truncated", function() {
98
+ expect($.print([1, 2, 3, 4], { max_array: 2 })).to(equal, '[ 1, 2, 2 more... ]');
99
+ });
100
+ });
101
+
102
+ describe('when the array has arrays as its elements', function() {
103
+ it("returns the recursively printed array", function() {
104
+ expect($.print([[]])).to(equal, '[ [] ]');
105
+ expect($.print([ [1, 2, 3], 4 ])).to(equal, '[ [ 1, 2, 3 ], 4 ]');
106
+ });
107
+ });
108
+
109
+ describe('when the array has objects as its elements', function() {
110
+ it("returns recursively printed array", function() {
111
+ expect($.print([{}])).to(equal, '[ {} ]');
112
+ expect($.print([ { foo: 'bar' }, 'baz' ])).to(equal, '[ { foo: "bar" }, "baz" ]');
113
+ });
114
+ });
115
+ });
116
+
117
+ describe('when given arguments', function() {
118
+ it("returns the printed array of elements ", function() {
119
+ var args = null;
120
+ (function(){ args = arguments })(1,2,3);
121
+ expect($.print(args)).to(equal, '[ 1, 2, 3 ]');
122
+ });
123
+ });
124
+
125
+ describe('when given a jQuery', function() {
126
+ it("returns the printed array of elements engirthed in '$()'", function() {
127
+ expect($.print($('<div></div>'))).to(equal, '$([ <div> ])');
128
+ });
129
+ });
130
+
131
+ describe('when given a NodeList', function() {
132
+ it("returns the printed array of elements in the list", function() {
133
+ expect($.print(document.getElementsByTagName('body'))).to(equal, '[ <body> ]');
134
+ });
135
+ });
136
+
137
+ describe('when given an object', function() {
138
+ it("returns the keys and values of the object, enraptured with curly braces", function() {
139
+ expect($.print({})).to(equal, '{}');
140
+ expect($.print({ foo: 1, bar: 2 })).to(equal, '{ foo: 1, bar: 2 }');
141
+ });
142
+
143
+ describe('when the values of the object are non-primitive', function() {
144
+ it("recursively prints the keys and values", function() {
145
+ expect($.print({ foo: [1, 2] })).to(equal, '{ foo: [ 1, 2 ] }');
146
+ });
147
+
148
+ describe('when the object has circular references', function() {
149
+ it("returns elipses for circularities", function() {
150
+ var circular = {};
151
+ circular[0] = circular;
152
+ expect($.print(circular)).to(equal, '{ 0: ... }');
153
+ });
154
+ });
155
+ });
156
+ });
157
+ });
158
+ });
File without changes
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <script src="../lib/jquery-1.2.6.js"></script>
4
+ <script src="../lib/jquery.fn.js"></script>
5
+ <script src="../lib/jquery.print.js"></script>
6
+ <script src="../lib/screw.builder.js"></script>
7
+ <script src="../lib/screw.matchers.js"></script>
8
+ <script src="../lib/screw.events.js"></script>
9
+ <script src="../lib/screw.behaviors.js"></script>
10
+ <script src="spec_helper.js"></script>
11
+ <script src="behaviors_spec.js"></script>
12
+ <script src="matchers_spec.js"></script>
13
+ <script src="print_spec.js"></script>
14
+
15
+ <link rel="stylesheet" href="../lib/screw.css">
16
+ </head>
17
+ <body></body>
18
+ </html>
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 Andy Kent
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ Smoke
2
+ =====
3
+ Smoke is a JavaScript mocking and stubbing framework. It has a familiar RSpec style interface and whilst it is perfectly capable of being used as a free-standing tool it comes complete with a plugin for the screw-unit testing framework.
4
+ Below are some getting started guides to get you on your way. See the included specs for further help.
5
+
6
+ Getting Started (With Screw.Unit)
7
+ ---------------------------------
8
+ See `spec/suite.html` and the test file `screw_integration_spec.js` for lots of real world usage examples.
9
+
10
+ but you will need to include the Smoke files and you can get straight to work using the mock() and spec() methods...
11
+
12
+ foo = {bar: function(attribute){return 'hello'}, baz:'goodbye'};
13
+ stub(foo, 'bar').and_return('hi!');
14
+ stub(foo, 'baz').and_set_to('welcome');
15
+ myMock = mock('test');
16
+ myMock.should_receive('foo').at_least('once').and_return('hello');
17
+ expect(foo.baz).to(equal, 'hi!');
18
+
19
+ Additionally Smoke now has a macro for mocking anonymous functions this is great for mocking and stubbing closures...
20
+
21
+ callback = mock_function();
22
+ callback.should_be_invoked().exactly('once');
23
+ $.bind('click', callback);
24
+ $.trigger('click');
25
+
26
+ Getting Started (Free Standing)
27
+ -------------------------------
28
+ Include the library files in your document...
29
+
30
+ <!-- require smoke -->
31
+ <script src="../lib/smoke.mock.js"></script>
32
+ <script src="../lib/smoke.stub.js"></script>
33
+
34
+ Create your stubs...
35
+
36
+ foo = {bar: function(attribute){return 'hello'}, baz:'goodbye'};
37
+ new Smoke.Stub(foo,'baz').and_set_to('boo');
38
+ new Smoke.Stub(foo,'bar').and_return('blah');
39
+
40
+ Create your mocks...
41
+
42
+ var myMock = Smoke.Mock();
43
+ var myMockFunction = Smoke.MockFunction();
44
+
45
+ Create your expectations...
46
+
47
+ myMock.should_receive('foo').with('bar').exactly(3, 'times').and_return('baz');
48
+
49
+ Check you expectations...
50
+
51
+ Smoke.checkExpectations();
52
+
53
+ More About Mocks
54
+ ----------------
55
+ Mocks are the main part of the Smoke framework. But Smoke.Mock() has a bit of a dual personality depending on if you pass it a value.
56
+
57
+ 1. *without any arguments* it will return a fresh Mock with no more than default Object methods. You will need to mock all your interactions and check all your expectations.
58
+ 2. *with an argument* it will return a 'Mocked' version of the object that was passed in. This is very useful if you just want to mock a single method on your object whilst leaving the rest intact. It's especially helpful for just carrying out expectations on existing objects without any mocking at all.
59
+
60
+ Smoke expectations are now destructive meaning that if you add an expectation then the previous method will not be invoked (if one exists) and undefined will be returned (unless you specify otherwise using and_return()).
61
+
62
+ Known Issues
63
+ ------------
64
+ * Whilst you can stub both functions and properties you can currently only carry out mock expectations on functions. Unfortunately I think this is a language limitation of JavaScript but if anyone has any bright ideas then I'm all ears.
65
+
66
+ Contact
67
+ -------
68
+ Please send patches, comments or suggestions to andrew.d.kent@gmail.com
@@ -0,0 +1,49 @@
1
+ Smoke = {
2
+ print: function(v) {
3
+ // use the jquery print plugin if it is available or fall back to toString();
4
+ return (jQuery && jQuery.print) ? jQuery.print(v) : v.toString();
5
+ },
6
+
7
+ printArguments: function(args) {
8
+ var a = [];
9
+ if (args === undefined) args = '';
10
+ if ((args && args.callee) || (args instanceof Array)) {
11
+ for(var i = 0; i < args.length; i++) {
12
+ a.push(Smoke.print(args[i]));
13
+ }
14
+ } else {
15
+ // Workaround for jQuery.print returning "null" when called with an empty string.
16
+ if (!args && (typeof args == 'string')) {
17
+ a.push('');
18
+ } else {
19
+ a.push(Smoke.print(args));
20
+ }
21
+ }
22
+ return '(' + a.join(', ') + ')';
23
+ },
24
+
25
+ argumentsToArray: function(args) {
26
+ return Array.prototype.slice.call(args);
27
+ },
28
+
29
+ compare: function(a, b) {
30
+ if (a === b) return true;
31
+ if (a instanceof Array) {
32
+ if (b.length != a.length) return false;
33
+ for (var i = 0; i < b.length; i++)
34
+ if (!this.compare(a[i], b[i])) return false;
35
+ } else if (a instanceof Object) {
36
+ for (var key in a)
37
+ if (!this.compare(a[key], b[key])) return false;
38
+ for (var key in b)
39
+ if (!this.compare(b[key], a[key])) return false;
40
+ } else {
41
+ return false;
42
+ }
43
+ return true;
44
+ },
45
+
46
+ compareArguments: function(a, b) {
47
+ return this.compare(Smoke.argumentsToArray(a), Smoke.argumentsToArray(b));
48
+ }
49
+ };
@@ -0,0 +1,219 @@
1
+ // Overide these functions for custom pass/fail behaviours
2
+ Smoke.passed = function(mock){
3
+ Smoke.passCount++;
4
+ };
5
+
6
+ Smoke.failed = function(mock, message){
7
+ Smoke.failCount++;
8
+ throw(message);
9
+ };
10
+
11
+ // Some helpers
12
+ Smoke.reset = function(){
13
+ Smoke.mocks = Smoke.mocks || [];
14
+ for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i]._resetMocks();
15
+ Smoke.mocks = [];
16
+ Smoke.passCount = 0;
17
+ Smoke.failCount = 0;
18
+ };
19
+ Smoke.reset();
20
+
21
+ Smoke.checkExpectations = function(){
22
+ for(var i=0; i<Smoke.mocks.length; i++) Smoke.mocks[i]._checkExpectations();
23
+ };
24
+
25
+ Smoke.Mock = function(originalObj) {
26
+ var obj = originalObj || {} ;
27
+ if (obj._expectations) return obj;
28
+ obj._expectations = {};
29
+ obj._valuesBeforeMocking = {};
30
+
31
+ obj.stub = function(attr){
32
+ if (!this._valuesBeforeMocking.hasOwnProperty(attr)) {
33
+ this._valuesBeforeMocking[attr] = this[attr];
34
+ }
35
+ return new Smoke.Stub(this, attr);
36
+ };
37
+
38
+ obj.should_receive = function(attr){
39
+ var expectation = new Smoke.Mock.Expectation(this, attr);
40
+ this._expectations[attr] = (this._expectations[attr] || []).concat([expectation]);
41
+ if (!this._valuesBeforeMocking.hasOwnProperty(attr)) {
42
+ this._valuesBeforeMocking[attr] = this[attr];
43
+ }
44
+ if(this._expectations[attr].length == 1) {
45
+ this[attr] = Smoke.Mock.Expectation.stub(this, attr);
46
+ }
47
+ return expectation;
48
+ };
49
+
50
+ obj.should_not_receive = function(attr){
51
+ return obj.should_receive(attr).exactly(0, "times");
52
+ };
53
+
54
+ obj.must_receive = function(attr) {
55
+ var expectation = obj.should_receive(attr);
56
+ expectation.at_least("once");
57
+ return expectation;
58
+ }
59
+
60
+ obj._checkExpectations = function(){
61
+ for(var e in this._expectations) {
62
+ var expectations = this._expectations[e]
63
+ for(var i=0; i < expectations.length; i++) expectations[i].check();
64
+ };
65
+ };
66
+
67
+ obj._resetMocks = function(){
68
+ for(var attr in this._valuesBeforeMocking) {
69
+ this[attr] = this._valuesBeforeMocking[attr];
70
+ }
71
+
72
+ delete this._valuesBeforeMocking;
73
+ delete this._expectations;
74
+ delete this._resetMocks;
75
+ delete this._checkExpectations;
76
+ delete this.stub;
77
+ delete this.should_receive;
78
+ };
79
+
80
+ Smoke.mocks.push(obj);
81
+ return obj;
82
+ };
83
+
84
+ Smoke.MockFunction = function(originalFunction, name) {
85
+ name = name || 'anonymous_function';
86
+ var mock = Smoke.Mock(function() {
87
+ return arguments.callee[name].apply(this, arguments);
88
+ });
89
+ mock[name] = (originalFunction || new Function());
90
+ mock.should_be_invoked = function() {
91
+ return this.should_receive(name);
92
+ }
93
+ mock.must_be_invoked = function() {
94
+ return this.must_receive(name);
95
+ }
96
+ mock.should_not_be_invoked = function() {
97
+ return this.should_not_receive(name);
98
+ }
99
+ return mock;
100
+ };
101
+
102
+ Smoke.Mock.Expectation = function(mock, attr) {
103
+ this._mock = mock;
104
+ this._attr = attr;
105
+ this.callCount = 0;
106
+ this.returnValue = undefined;
107
+ this.callerArgs = undefined;
108
+ this.hasReturnValue = false;
109
+ };
110
+
111
+ Smoke.Mock.Expectation.stub = function(mock, attr) {
112
+ return function() {
113
+ return function() {
114
+ var matched, return_value, args = arguments;
115
+ jQuery.each(this, function() {
116
+ if (!matched) {
117
+ if (this.run(args)) {
118
+ matched = true;
119
+ return_value = this.returnValue;
120
+ }
121
+ }
122
+ });
123
+ if (!matched) {
124
+ this[0].argumentMismatchError(args)
125
+ }
126
+ return return_value;
127
+ }.apply(mock._expectations[attr].slice(0).reverse(), arguments);
128
+ }
129
+ }
130
+
131
+
132
+ Smoke.Mock.Expectation.prototype = {
133
+ exactly: function(count,type){
134
+ // type isn't used for now, it's just syntax ;)
135
+ this.minCount = this.maxCount = undefined;
136
+ this.exactCount = this.parseCount(count);
137
+ return this;
138
+ },
139
+ at_most: function(count,type){
140
+ this.maxCount = this.parseCount(count);
141
+ return this;
142
+ },
143
+ at_least: function(count,type){
144
+ this.minCount = this.parseCount(count);
145
+ return this;
146
+ },
147
+ with_arguments: function(){
148
+ this.callerArgs = arguments;
149
+ return this
150
+ },
151
+ with_any_arguments: function(){
152
+ this.acceptAnyArguments = true;
153
+ return this
154
+ },
155
+ run: function(args){
156
+ if (this.throwException) {
157
+ throw this.throwException;
158
+ }
159
+ else if (this.executeFunction) {
160
+ this.callCount+=1;
161
+ this.hasReturnValue = true;
162
+ this.returnValue = this.executeFunction.apply(null, args);
163
+ return true;
164
+ }
165
+ else if(this.acceptAnyArguments) {
166
+ this.callCount+=1;
167
+ return true;
168
+ }
169
+ else if((this.callerArgs === undefined) || Smoke.compareArguments(args, this.callerArgs)) {
170
+ return !!(this.callCount+=1);
171
+ };
172
+ return false
173
+ },
174
+ and_return: function(v){
175
+ this.hasReturnValue = true;
176
+ this.returnValue = v;
177
+ },
178
+ and_throw: function(e){
179
+ this.throwException = e;
180
+ return this;
181
+ },
182
+ and_execute: function(fn){
183
+ this.executeFunction = fn;
184
+ return this;
185
+ },
186
+ check: function(){
187
+ if(this.exactCount!=undefined) this.checkExactCount();
188
+ if(this.minCount!=undefined) this.checkMinCount();
189
+ if(this.maxCount!=undefined) this.checkMaxCount();
190
+ },
191
+ checkExactCount: function(){
192
+ if(this.exactCount==this.callCount) Smoke.passed(this)//console.log('Mock passed!')
193
+ else Smoke.failed(this, 'expected '+this.methodSignature()+' to be called exactly '+this.exactCount+" times but it got called "+this.callCount+' times');
194
+ },
195
+ checkMinCount: function(){
196
+ if(this.minCount<=this.callCount) Smoke.passed(this);
197
+ else Smoke.failed(this, 'expected '+this.methodSignature()+' to be called at least '+this.minCount+" times but it only got called "+this.callCount+' times');
198
+ },
199
+ checkMaxCount: function(){
200
+ if(this.maxCount>=this.callCount) Smoke.passed(this);//console.log('Mock passed!')
201
+ else Smoke.failed(this, 'expected '+this.methodSignature()+' to be called at most '+this.maxCount+" times but it actually got called "+this.callCount+' times');
202
+ },
203
+ argumentMismatchError: function(args) {
204
+ Smoke.failed(this, 'expected ' + this._attr + ' with ' + Smoke.printArguments(this.callerArgs) + ' but received it with ' + Smoke.printArguments(args));
205
+ },
206
+ methodSignature: function(){
207
+ return this._attr + Smoke.printArguments(this.callerArgs);
208
+ },
209
+ parseCount: function(c){
210
+ switch(c){
211
+ case 'once':
212
+ return 1;
213
+ case 'twice':
214
+ return 2;
215
+ default:
216
+ return c;
217
+ }
218
+ }
219
+ };
@@ -0,0 +1,29 @@
1
+ Smoke.Stub = function(obj,attr) {
2
+ this.obj = obj;
3
+ this.attribute = attr;
4
+ this.and_return(this.defaultReturn);
5
+ };
6
+
7
+ Smoke.Stub.prototype = {
8
+ defaultReturn: null,
9
+ property: function(p){
10
+ this.property = p;
11
+ this.and_set_to(this.defaultReturn);
12
+ return this
13
+ },
14
+ method: function(f){
15
+ this.func = f;
16
+ this.and_return(this.defaultReturn);
17
+ return this
18
+ },
19
+ and_return: function(v){
20
+ this.obj[this.attribute] = function() {
21
+ return v
22
+ };
23
+ return this.obj
24
+ },
25
+ and_set_to: function(v){
26
+ this.obj[this.attribute] = v;
27
+ return this.obj
28
+ }
29
+ };
@@ -0,0 +1,26 @@
1
+ // This is a lightweight bridge between Smoke and Screw.Unit.
2
+ // It shadows mocking and stubbing onto the matchers to make them available within tests.
3
+
4
+ Screw.Matchers.mock = function(m) {
5
+ return Smoke.Mock(m);
6
+ };
7
+
8
+ Screw.Matchers.mock_function = function(func,name) {
9
+ return Smoke.MockFunction(func,name);
10
+ };
11
+
12
+ Screw.Matchers.stub = function(obj, attr) {
13
+ return new Smoke.Stub(obj,attr);
14
+ };
15
+
16
+ (function($) {
17
+ $(Screw).bind("before", function(){
18
+ function checkAndResetSmoke() {
19
+ Smoke.checkExpectations();
20
+ Smoke.reset();
21
+ }
22
+
23
+ $('.it').bind('passed', function(){ checkAndResetSmoke() });
24
+ $('.it').bind('failed', function(){ Smoke.reset() });
25
+ });
26
+ })(jQuery);