@@ -65,23 +65,25 @@ jQuery[^jQuery]在发布版本``2.1.3``,一共有152个commit。我们可以
65
65
66
66
通常我们都会找Document,如果没有的话,你会找什么?看源代码,还是看测试?
67
67
68
- it("specifying response when you need it", function (done) {
69
- var doneFn = jasmine.createSpy("success");
70
-
71
- lettuce.get('/some/cool/url', function (result) {
72
- expect(result).toEqual("awesome response");
73
- done();
74
- });
75
-
76
- expect(jasmine.Ajax.requests.mostRecent().url).toBe('/some/cool/url');
77
- expect(doneFn).not.toHaveBeenCalled();
78
-
79
- jasmine.Ajax.requests.mostRecent().respondWith({
80
- "status": 200,
81
- "contentType": 'text/plain',
82
- "responseText": 'awesome response'
83
- });
84
- });
68
+ ``` javascript
69
+ it (" specifying response when you need it" , function (done ) {
70
+ var doneFn = jasmine .createSpy (" success" );
71
+
72
+ lettuce .get (' /some/cool/url' , function (result ) {
73
+ expect (result).toEqual (" awesome response" );
74
+ done ();
75
+ });
76
+
77
+ expect (jasmine .Ajax .requests .mostRecent ().url ).toBe (' /some/cool/url' );
78
+ expect (doneFn).not .toHaveBeenCalled ();
79
+
80
+ jasmine .Ajax .requests .mostRecent ().respondWith ({
81
+ " status" : 200 ,
82
+ " contentType" : ' text/plain' ,
83
+ " responseText" : ' awesome response'
84
+ });
85
+ });
86
+ ```
85
87
86
88
代码来源: [ https://github.com/phodal/lettuce ] ( https://github.com/phodal/lettuce )
87
89
@@ -97,17 +99,19 @@ jQuery[^jQuery]在发布版本``2.1.3``,一共有152个commit。我们可以
97
99
98
100
也许你已经知道了`` Selenium `` 、`` Jasmine `` 、`` Cucumber `` 等等的框架,看到过类似于下面的测试
99
101
100
- Ajax
101
- ✓ specifying response when you need it
102
- ✓ specifying html when you need it
103
- ✓ should be post to some where
104
- Class
105
- ✓ respects instanceof
106
- ✓ inherits methods (also super)
107
- ✓ extend methods
108
- Effect
109
- ✓ should be able fadein elements
110
- ✓ should be able fadeout elements
102
+ ```
103
+ Ajax
104
+ ✓ specifying response when you need it
105
+ ✓ specifying html when you need it
106
+ ✓ should be post to some where
107
+ Class
108
+ ✓ respects instanceof
109
+ ✓ inherits methods (also super)
110
+ ✓ extend methods
111
+ Effect
112
+ ✓ should be able fadein elements
113
+ ✓ should be able fadeout elements
114
+ ```
111
115
112
116
代码来源: [ https://github.com/phodal/lettuce ] ( https://github.com/phodal/lettuce )
113
117
@@ -123,17 +127,18 @@ lettuce.js | 98.58% (209 / 212)| 82.98%(78 / 94) | 100.00% (54 / 54) | 98.58% (2
123
127
124
128
虽然node.js不算是一门语言,但是因为我们用的node,下面的是一个简单的`` .travis.yml `` 示例:
125
129
126
- language: node_js
127
- node_js:
128
- - "0.10"
129
-
130
- notifications:
131
- email: false
130
+ ``` yml
131
+ language : node_js
132
+ node_js :
133
+ - "0.10"
132
134
133
- before_install: npm install -g grunt-cli
134
- install: npm install
135
- after_success: CODECLIMATE_REPO_TOKEN=321480822fc37deb0de70a11931b4cb6a2a3cc411680e8f4569936ac8ffbb0ab codeclimate < coverage/lcov.info
135
+ notifications :
136
+ email: false
136
137
138
+ before_install : npm install -g grunt-cli
139
+ install : npm install
140
+ after_success : CODECLIMATE_REPO_TOKEN=321480822fc37deb0de70a11931b4cb6a2a3cc411680e8f4569936ac8ffbb0ab codeclimate < coverage/lcov.info
141
+ ` ` `
137
142
138
143
代码来源: [https://github.com/phodal/lettuce](https://github.com/phodal/lettuce)
139
144
@@ -153,28 +158,30 @@ CI对于一个开发者在不同城市开发同一项目上来说是很重要的
153
158
154
159
先看看上面的ajax类:
155
160
156
- Lettuce.get = function (url, callback) {
157
- Lettuce.send(url, 'GET', callback);
158
- };
159
-
160
- Lettuce.send = function (url, method, callback, data) {
161
- data = data || null;
162
- var request = new XMLHttpRequest();
163
- if (callback instanceof Function) {
164
- request.onreadystatechange = function () {
165
- if (request.readyState === 4 && (request.status === 200 || request.status === 0)) {
166
- callback(request.responseText);
167
- }
168
- };
169
- }
170
- request.open(method, url, true);
171
- if (data instanceof Object) {
172
- data = JSON.stringify(data);
173
- request.setRequestHeader('Content-Type', 'application/json');
174
- }
175
- request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
176
- request.send(data);
177
- };
161
+ ` ` ` javascript
162
+ Lettuce.get = function (url, callback) {
163
+ Lettuce.send(url, 'GET', callback);
164
+ };
165
+
166
+ Lettuce.send = function (url, method, callback, data) {
167
+ data = data || null;
168
+ var request = new XMLHttpRequest();
169
+ if (callback instanceof Function) {
170
+ request.onreadystatechange = function () {
171
+ if (request.readyState === 4 && (request.status === 200 || request.status === 0)) {
172
+ callback(request.responseText);
173
+ }
174
+ };
175
+ }
176
+ request.open(method, url, true);
177
+ if (data instanceof Object) {
178
+ data = JSON.stringify(data);
179
+ request.setRequestHeader('Content-Type', 'application/json');
180
+ }
181
+ request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
182
+ request.send(data);
183
+ };
184
+ ```
178
185
179
186
代码来源: [ https://github.com/phodal/lettuce ] ( https://github.com/phodal/lettuce )
180
187
0 commit comments