validate-website 1.8.1 → 1.10.0
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.
- checksums.yaml +4 -4
- data/History.md +37 -0
- data/LICENSE +1 -1
- data/README.md +38 -25
- data/Rakefile +5 -1
- data/bin/validate-website +1 -1
- data/bin/validate-website-static +1 -1
- data/lib/validate_website.rb +2 -0
- data/lib/validate_website/colorful_messages.rb +3 -0
- data/lib/validate_website/core.rb +14 -6
- data/lib/validate_website/crawl.rb +8 -1
- data/lib/validate_website/option_parser.rb +58 -54
- data/lib/validate_website/runner.rb +3 -1
- data/lib/validate_website/static.rb +19 -9
- data/lib/validate_website/static_link.rb +4 -2
- data/lib/validate_website/utils.rb +3 -0
- data/lib/validate_website/validator.rb +24 -27
- data/lib/validate_website/validator_class_methods.rb +3 -0
- data/lib/validate_website/version.rb +1 -1
- data/man/man1/validate-website-static.1 +17 -8
- data/man/man1/validate-website.1 +17 -8
- data/test/core_test.rb +4 -2
- data/test/crawler_test.rb +36 -17
- data/test/data/html5-fail.html +0 -337
- data/test/static_test.rb +26 -6
- data/test/test_helper.rb +9 -2
- data/test/validator_test.rb +26 -24
- data/test/webmock_helper.rb +4 -2
- metadata +34 -35
data/test/data/html5-fail.html
CHANGED
@@ -118,333 +118,6 @@
|
|
118
118
|
</div>
|
119
119
|
</div>
|
120
120
|
|
121
|
-
<script type="text/javascript">
|
122
|
-
include = function() {
|
123
|
-
|
124
|
-
// save references to save a few bytes
|
125
|
-
var args = arguments;
|
126
|
-
var doc = document;
|
127
|
-
|
128
|
-
var toLoad = args.length; // load this many scripts
|
129
|
-
var lastArgument = args[toLoad - 1];
|
130
|
-
var hasCallback = lastArgument.call; // is the last arg a callback?
|
131
|
-
if (hasCallback) {
|
132
|
-
toLoad--;
|
133
|
-
}
|
134
|
-
|
135
|
-
function onScriptLoaded() {
|
136
|
-
var readyState = this.readyState; // we test for "complete" or "loaded" if on IE
|
137
|
-
if (!readyState || /ded|te/.test(readyState)) {
|
138
|
-
toLoad--;
|
139
|
-
if (!toLoad && hasCallback) {
|
140
|
-
lastArgument();
|
141
|
-
}
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
for (var i = 0; i < toLoad; i++) {
|
146
|
-
|
147
|
-
var script = doc.createElement('script');
|
148
|
-
script.src = arguments[i];
|
149
|
-
script.async = true;
|
150
|
-
script.onload = script.onerror = script.onreadystatechange = onScriptLoaded;
|
151
|
-
(
|
152
|
-
doc.head ||
|
153
|
-
doc.getElementsByTagName('head')[0]
|
154
|
-
).appendChild(script);
|
155
|
-
|
156
|
-
}
|
157
|
-
|
158
|
-
};
|
159
|
-
|
160
|
-
|
161
|
-
include("https://cdn.jsdelivr.net/ace/1.1.3/noconflict/ace.js", function () {
|
162
|
-
include("https://cdn.jsdelivr.net/ace/1.1.3/noconflict/mode-rust.js", function () {
|
163
|
-
(function () {
|
164
|
-
"use strict";
|
165
|
-
// ECMAScript 6 Backwards compatability
|
166
|
-
if (typeof String.prototype.startsWith !== 'function') {
|
167
|
-
String.prototype.startsWith = function(str) {
|
168
|
-
return this.slice(0, str.length) === str;
|
169
|
-
};
|
170
|
-
}
|
171
|
-
|
172
|
-
// Regex for finding new lines
|
173
|
-
var newLineRegex = /(?:\r\n|\r|\n)/g;
|
174
|
-
|
175
|
-
// Fetching DOM items
|
176
|
-
var activeCode = document.getElementById("active-code");
|
177
|
-
var editorDiv = document.getElementById("editor");
|
178
|
-
var staticCode = document.getElementById("static-code");
|
179
|
-
var runButton = document.getElementById("run-code");
|
180
|
-
var resultDiv = document.getElementById("result");
|
181
|
-
var playLink = document.getElementById("playlink");
|
182
|
-
|
183
|
-
// Background colors for program result on success/error
|
184
|
-
var successColor = "#E2EEF6";
|
185
|
-
var errorColor = "#F6E2E2";
|
186
|
-
var warningColor = "#FFFBCB";
|
187
|
-
|
188
|
-
// Message to show when the program is running
|
189
|
-
var runningMsg = resultDiv.getAttribute("data-msg-running") || "Running...";
|
190
|
-
|
191
|
-
// Error message to return when there's a server failure
|
192
|
-
var errMsg = "The server encountered an error while running the program.";
|
193
|
-
|
194
|
-
// Stores ACE editor markers (highights) for errors
|
195
|
-
var markers = [];
|
196
|
-
|
197
|
-
// Status codes, because there are no enums in Javascript
|
198
|
-
var SUCCESS = 0;
|
199
|
-
var ERROR = 1;
|
200
|
-
var WARNING = 2;
|
201
|
-
|
202
|
-
// JS exists, display ACE editor
|
203
|
-
staticCode.style.display = "none";
|
204
|
-
activeCode.style.display = "block";
|
205
|
-
|
206
|
-
// Setting up ace editor
|
207
|
-
var editor = ace.edit("editor");
|
208
|
-
var Range = ace.require('ace/range').Range;
|
209
|
-
editor.setTheme("ace/theme/chrome");
|
210
|
-
editor.getSession().setMode("ace/mode/rust");
|
211
|
-
editor.setShowPrintMargin(false);
|
212
|
-
editor.renderer.setShowGutter(false);
|
213
|
-
editor.setHighlightActiveLine(false);
|
214
|
-
|
215
|
-
// Changes the height of the editor to match its contents
|
216
|
-
function updateEditorHeight() {
|
217
|
-
// https://stackoverflow.com/questions/11584061/
|
218
|
-
var newHeight = editor.getSession().getScreenLength()
|
219
|
-
* editor.renderer.lineHeight
|
220
|
-
+ editor.renderer.scrollBar.getWidth();
|
221
|
-
|
222
|
-
editorDiv.style.height = Math.ceil(newHeight).toString() + "px";
|
223
|
-
editor.resize();
|
224
|
-
}
|
225
|
-
|
226
|
-
// Set initial size to match initial content
|
227
|
-
updateEditorHeight();
|
228
|
-
|
229
|
-
// Safely remove all content from the result div
|
230
|
-
function clearResultDiv() {
|
231
|
-
// Clearing the result div will break our reference to
|
232
|
-
// the playlink icon, so let's save it if it exists
|
233
|
-
var newPlayLink = document.getElementById("playlink");
|
234
|
-
if (newPlayLink) {
|
235
|
-
playLink = resultDiv.removeChild(newPlayLink);
|
236
|
-
}
|
237
|
-
resultDiv.innerHTML = "";
|
238
|
-
}
|
239
|
-
|
240
|
-
function escapeHTML(unsafe) {
|
241
|
-
return unsafe
|
242
|
-
.replace(/&/g, "&")
|
243
|
-
.replace(/</g, "<")
|
244
|
-
.replace(/>/g, ">")
|
245
|
-
.replace(/"/g, """)
|
246
|
-
.replace(/'/g, "'")
|
247
|
-
.replace(newLineRegex, '<br />');
|
248
|
-
}
|
249
|
-
|
250
|
-
// Dispatches a XMLHttpRequest to the Rust playpen, running the program, and
|
251
|
-
// issues a callback to `callback` with the result (or null on error)
|
252
|
-
function runProgram(program, callback) {
|
253
|
-
var req = new XMLHttpRequest();
|
254
|
-
var data = JSON.stringify({
|
255
|
-
version: "beta",
|
256
|
-
optimize: "0",
|
257
|
-
code: program
|
258
|
-
});
|
259
|
-
|
260
|
-
req.timeout = 6000;
|
261
|
-
|
262
|
-
// console.log("Sending", data);
|
263
|
-
req.open('POST', "https://play.rust-lang.org/evaluate.json", true);
|
264
|
-
req.onload = function(e) {
|
265
|
-
var statusCode = false;
|
266
|
-
var result = null;
|
267
|
-
|
268
|
-
if (req.readyState === 4 && req.status === 200) {
|
269
|
-
result = JSON.parse(req.response);
|
270
|
-
|
271
|
-
// handle application errors from playpen
|
272
|
-
if (typeof result['error'] === 'string') {
|
273
|
-
statusCode = ERROR;
|
274
|
-
result = 'Playpen Error: ' + result['error'];
|
275
|
-
} else if (typeof result['result'] === 'string') {
|
276
|
-
statusCode = SUCCESS;
|
277
|
-
result = result['result'];
|
278
|
-
|
279
|
-
// handle rustc errors/warnings
|
280
|
-
// Need server support to get an accurate version of this.
|
281
|
-
if (result.indexOf("error:") !== -1) {
|
282
|
-
statusCode = ERROR;
|
283
|
-
} else if (result.indexOf("warning:") !== -1) {
|
284
|
-
statusCode = WARNING;
|
285
|
-
}
|
286
|
-
}
|
287
|
-
}
|
288
|
-
|
289
|
-
callback(statusCode, result);
|
290
|
-
};
|
291
|
-
|
292
|
-
req.onerror = function(e) {
|
293
|
-
callback(false, null);
|
294
|
-
};
|
295
|
-
|
296
|
-
req.ontimeout = function(e) {
|
297
|
-
var statusCode = ERROR;
|
298
|
-
var result = "play.rust-lang.org not responding, please check back later";
|
299
|
-
|
300
|
-
callback(statusCode, result);
|
301
|
-
}
|
302
|
-
|
303
|
-
req.setRequestHeader("Content-Type", "application/json");
|
304
|
-
req.send(data);
|
305
|
-
}
|
306
|
-
|
307
|
-
// The callback to runProgram
|
308
|
-
function handleResult(statusCode, message) {
|
309
|
-
// Dispatch depending on result type
|
310
|
-
if (result == null) {
|
311
|
-
clearResultDiv();
|
312
|
-
resultDiv.style.backgroundColor = errorColor;
|
313
|
-
resultDiv.innerHTML = errMsg;
|
314
|
-
} else if (statusCode === SUCCESS) {
|
315
|
-
handleSuccess(message);
|
316
|
-
} else if (statusCode === WARNING) {
|
317
|
-
handleWarning(message);
|
318
|
-
} else {
|
319
|
-
handleError(message);
|
320
|
-
}
|
321
|
-
}
|
322
|
-
|
323
|
-
// Called on successful program run: display output and playground icon
|
324
|
-
function handleSuccess(message) {
|
325
|
-
resultDiv.style.backgroundColor = successColor;
|
326
|
-
displayOutput(escapeHTML(message), editor.getValue());
|
327
|
-
}
|
328
|
-
|
329
|
-
// Called when program run results in warning(s)
|
330
|
-
function handleWarning(message) {
|
331
|
-
resultDiv.style.backgroundColor = warningColor;
|
332
|
-
handleProblem(message, "warning");
|
333
|
-
}
|
334
|
-
|
335
|
-
// Called when program run results in error(s)
|
336
|
-
function handleError(message) {
|
337
|
-
resultDiv.style.backgroundColor = errorColor;
|
338
|
-
handleProblem(message, "error");
|
339
|
-
}
|
340
|
-
|
341
|
-
// Called on unsuccessful program run. Detects and prints problems (either
|
342
|
-
// warnings or errors) in program output and highlights relevant lines and text
|
343
|
-
// in the code.
|
344
|
-
function handleProblem(message, problem) {
|
345
|
-
// Getting list of ranges with problems
|
346
|
-
var lines = message.split(newLineRegex);
|
347
|
-
|
348
|
-
// Cleaning up the message: keeps only relevant problem output.
|
349
|
-
var cleanMessage = lines.filter(function(line) {
|
350
|
-
return !line.trim().startsWith("--> <anon>")
|
351
|
-
&& !line.startsWith("playpen:")
|
352
|
-
&& !line.trim().startsWith("error: aborting");
|
353
|
-
}).map(function(line) {
|
354
|
-
return escapeHTML(line);
|
355
|
-
}).filter(function(line) {
|
356
|
-
return line != "";
|
357
|
-
}).map(function(line) {
|
358
|
-
return line.replace(/ /g, '\u00a0\u00a0');
|
359
|
-
}).join("<br />");
|
360
|
-
|
361
|
-
// Get all of the row:col in the message.
|
362
|
-
var errorLines = lines.filter(function(line) {
|
363
|
-
return line.indexOf("--> <anon>") !== -1;
|
364
|
-
}).map(function(line) {
|
365
|
-
var lineIndex = line.indexOf(":");
|
366
|
-
if (lineIndex !== -1) {
|
367
|
-
return line.slice(lineIndex);
|
368
|
-
}
|
369
|
-
|
370
|
-
return "";
|
371
|
-
}).filter(function(line) {
|
372
|
-
return line != "";
|
373
|
-
});
|
374
|
-
|
375
|
-
// Setting message
|
376
|
-
displayOutput(cleanMessage, editor.getValue());
|
377
|
-
|
378
|
-
// Highlighting the lines
|
379
|
-
var ranges = parseProblems(errorLines);
|
380
|
-
markers = ranges.map(function(range) {
|
381
|
-
return editor.getSession().addMarker(range, "ace-" + problem + "-line",
|
382
|
-
"fullLine", false);
|
383
|
-
});
|
384
|
-
|
385
|
-
// Highlighting the specific text
|
386
|
-
markers = markers.concat(ranges.map(function(range) {
|
387
|
-
return editor.getSession().addMarker(range, "ace-" + problem + "-text",
|
388
|
-
"text", false);
|
389
|
-
}));
|
390
|
-
}
|
391
|
-
|
392
|
-
// Parses a problem message returning a list of ranges (row:col, row:col) where
|
393
|
-
// problems in the code have occured.
|
394
|
-
function parseProblems(lines) {
|
395
|
-
var ranges = [];
|
396
|
-
for (var i in lines) {
|
397
|
-
var line = lines[i];
|
398
|
-
var parts = line.split(/:\s?|\s+/, 5).slice(1, 5);
|
399
|
-
var ip = parts.map(function(p) { return parseInt(p, 10) - 1; });
|
400
|
-
console.log("line:", line, parts, ip);
|
401
|
-
ranges.push(new Range(ip[0], ip[1], ip[2], ip[3]));
|
402
|
-
}
|
403
|
-
|
404
|
-
return ranges;
|
405
|
-
}
|
406
|
-
|
407
|
-
// Registering handler for run button click
|
408
|
-
runButton.addEventListener("click", function(ev) {
|
409
|
-
resultDiv.style.display = "block";
|
410
|
-
clearResultDiv();
|
411
|
-
resultDiv.innerHTML = runningMsg;
|
412
|
-
|
413
|
-
// clear previous markers, if any
|
414
|
-
markers.map(function(id) { editor.getSession().removeMarker(id); });
|
415
|
-
|
416
|
-
// Get the code, run the program
|
417
|
-
var program = editor.getValue();
|
418
|
-
runProgram(program, handleResult);
|
419
|
-
});
|
420
|
-
|
421
|
-
// Display an output message and a link to the Rust playground
|
422
|
-
function displayOutput(message, program) {
|
423
|
-
var programUrl = "https://play.rust-lang.org/?code=" +
|
424
|
-
encodeURIComponent(program) + "&run=1";
|
425
|
-
playLink.href = programUrl;
|
426
|
-
|
427
|
-
clearResultDiv(); // clear resultDiv, then add
|
428
|
-
resultDiv.appendChild(playLink); // playLink icon and message
|
429
|
-
resultDiv.innerHTML += message;
|
430
|
-
}
|
431
|
-
|
432
|
-
// Highlight active line when focused
|
433
|
-
editor.on('focus', function() {
|
434
|
-
editor.setHighlightActiveLine(true);
|
435
|
-
});
|
436
|
-
|
437
|
-
// Don't when not
|
438
|
-
editor.on('blur', function() {
|
439
|
-
editor.setHighlightActiveLine(false);
|
440
|
-
});
|
441
|
-
}());
|
442
|
-
|
443
|
-
});
|
444
|
-
});
|
445
|
-
</script>
|
446
|
-
|
447
|
-
|
448
121
|
<footer>
|
449
122
|
<p>Our site in other languages:
|
450
123
|
<a href="/en-US/">English</a>,
|
@@ -462,15 +135,5 @@
|
|
462
135
|
</p>
|
463
136
|
</footer>
|
464
137
|
|
465
|
-
<script>
|
466
|
-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
467
|
-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
468
|
-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
469
|
-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
470
|
-
|
471
|
-
ga('create', 'UA-58390457-1', 'auto');
|
472
|
-
ga('send', 'pageview');
|
473
|
-
|
474
|
-
</script>
|
475
138
|
</body>
|
476
139
|
</html>
|
data/test/static_test.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('test_helper', __dir__)
|
2
4
|
|
3
5
|
# rubocop:disable Metrics/BlockLength
|
4
6
|
describe ValidateWebsite::Static do
|
@@ -17,7 +19,7 @@ describe ValidateWebsite::Static do
|
|
17
19
|
not_found: false,
|
18
20
|
exclude: /data|example/)
|
19
21
|
end
|
20
|
-
@validate_website.history_count.must_equal 0
|
22
|
+
_(@validate_website.history_count).must_equal 0
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'no space in directory name' do
|
@@ -28,7 +30,7 @@ describe ValidateWebsite::Static do
|
|
28
30
|
markup: false,
|
29
31
|
not_found: false)
|
30
32
|
end
|
31
|
-
@validate_website.not_founds_count.must_equal 0
|
33
|
+
_(@validate_website.not_founds_count).must_equal 0
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'not found' do
|
@@ -40,7 +42,25 @@ describe ValidateWebsite::Static do
|
|
40
42
|
markup: false,
|
41
43
|
not_found: true)
|
42
44
|
end
|
43
|
-
@validate_website.not_founds_count.must_equal 213
|
45
|
+
_(@validate_website.not_founds_count).must_equal 213
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can change validator' do
|
50
|
+
validator_res = File.join('test', 'data', 'validator.nu-failure.json')
|
51
|
+
stub_request(:any,
|
52
|
+
/#{ValidateWebsite::Validator.html5_validator_service_url}/)
|
53
|
+
.to_return(body: File.open(validator_res).read)
|
54
|
+
pattern = File.join(File.dirname(__FILE__), 'data',
|
55
|
+
'html5-fail.html')
|
56
|
+
Dir.chdir('test/data') do
|
57
|
+
_out, _err = capture_io do
|
58
|
+
@validate_website.crawl(pattern: pattern,
|
59
|
+
site: 'http://w3.org/',
|
60
|
+
ignore: /Warning/,
|
61
|
+
html5_validator: :nu)
|
62
|
+
end
|
63
|
+
_(@validate_website.errors_count).must_equal 1
|
44
64
|
end
|
45
65
|
end
|
46
66
|
|
@@ -53,7 +73,7 @@ describe ValidateWebsite::Static do
|
|
53
73
|
site: 'http://w3.org/',
|
54
74
|
ignore: /height|width|Length/)
|
55
75
|
end
|
56
|
-
@validate_website.errors_count.must_equal 0
|
76
|
+
_(@validate_website.errors_count).must_equal 0
|
57
77
|
end
|
58
78
|
end
|
59
79
|
|
@@ -67,7 +87,7 @@ describe ValidateWebsite::Static do
|
|
67
87
|
markup: false,
|
68
88
|
css_syntax: true)
|
69
89
|
end
|
70
|
-
@validate_website.errors_count.must_equal 1
|
90
|
+
_(@validate_website.errors_count).must_equal 1
|
71
91
|
end
|
72
92
|
end
|
73
93
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
begin
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
rescue LoadError
|
7
|
+
warn 'coveralls not loaded'
|
8
|
+
end
|
9
|
+
|
3
10
|
require 'minitest/autorun'
|
4
11
|
require 'spidr'
|
5
12
|
|
6
13
|
require 'validate_website/core'
|
7
14
|
|
8
|
-
require File.expand_path('
|
15
|
+
require File.expand_path('webmock_helper', __dir__)
|
9
16
|
|
10
|
-
TEST_DOMAIN = 'http://www.example.com/'
|
17
|
+
TEST_DOMAIN = 'http://www.example.com/'
|
11
18
|
ENV['LC_ALL'] = 'C.UTF-8' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
data/test/validator_test.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('test_helper', __dir__)
|
2
4
|
|
3
5
|
# rubocop:disable Metrics/BlockLength
|
4
6
|
describe ValidateWebsite::Validator do
|
@@ -14,15 +16,15 @@ describe ValidateWebsite::Validator do
|
|
14
16
|
name = 'w3.org-xhtml1-strict-errors'
|
15
17
|
file = File.join('test', 'data', "#{name}.html")
|
16
18
|
page = FakePage.new(name,
|
17
|
-
body: open(file).read,
|
19
|
+
body: File.open(file).read,
|
18
20
|
content_type: 'text/html')
|
19
21
|
@xhtml1_page = @http.get_page(page.url)
|
20
22
|
ignore = /width|height|Length/
|
21
23
|
validator = subject.new(@xhtml1_page.doc,
|
22
24
|
@xhtml1_page.body,
|
23
25
|
ignore: ignore)
|
24
|
-
validator.valid
|
25
|
-
validator.errors.must_equal []
|
26
|
+
_(validator.valid?).must_equal true
|
27
|
+
_(validator.errors).must_equal []
|
26
28
|
end
|
27
29
|
|
28
30
|
it 'xhtml1-strict should be valid' do
|
@@ -30,17 +32,17 @@ describe ValidateWebsite::Validator do
|
|
30
32
|
dtd_uri = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
31
33
|
file = File.join('test', 'data', "#{name}.html")
|
32
34
|
page = FakePage.new(name,
|
33
|
-
body: open(file).read,
|
35
|
+
body: File.open(file).read,
|
34
36
|
content_type: 'text/html')
|
35
37
|
@xhtml1_page = @http.get_page(page.url)
|
36
38
|
ignore = /width|height|Length/
|
37
39
|
validator = subject.new(@xhtml1_page.doc,
|
38
40
|
@xhtml1_page.body,
|
39
41
|
ignore: ignore)
|
40
|
-
validator.dtd.system_id.must_equal dtd_uri
|
41
|
-
validator.namespace.must_equal name
|
42
|
-
validator.valid
|
43
|
-
validator.errors.must_equal []
|
42
|
+
_(validator.dtd.system_id).must_equal dtd_uri
|
43
|
+
_(validator.namespace).must_equal name
|
44
|
+
_(validator.valid?).must_equal true
|
45
|
+
_(validator.errors).must_equal []
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -49,18 +51,18 @@ describe ValidateWebsite::Validator do
|
|
49
51
|
before do
|
50
52
|
validator_res = File.join('test', 'data', 'validator.nu-success.json')
|
51
53
|
stub_request(:any, /#{subject.html5_validator_service_url}/)
|
52
|
-
.to_return(body: open(validator_res).read)
|
54
|
+
.to_return(body: File.open(validator_res).read)
|
53
55
|
end
|
54
56
|
it 'html5 should be valid' do
|
55
57
|
name = 'html5'
|
56
58
|
file = File.join('test', 'data', "#{name}.html")
|
57
59
|
page = FakePage.new(name,
|
58
|
-
body: open(file).read,
|
60
|
+
body: File.open(file).read,
|
59
61
|
content_type: 'text/html')
|
60
62
|
@html5_page = @http.get_page(page.url)
|
61
63
|
validator = subject.new(@html5_page.doc,
|
62
64
|
@html5_page.body)
|
63
|
-
validator.valid
|
65
|
+
_(validator.valid?).must_equal true
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -68,11 +70,11 @@ describe ValidateWebsite::Validator do
|
|
68
70
|
before do
|
69
71
|
validator_res = File.join('test', 'data', 'validator.nu-failure.json')
|
70
72
|
stub_request(:any, /#{subject.html5_validator_service_url}/)
|
71
|
-
.to_return(body: open(validator_res).read)
|
73
|
+
.to_return(body: File.open(validator_res).read)
|
72
74
|
name = 'html5-fail'
|
73
75
|
file = File.join('test', 'data', "#{name}.html")
|
74
76
|
page = FakePage.new(name,
|
75
|
-
body: open(file).read,
|
77
|
+
body: File.open(file).read,
|
76
78
|
content_type: 'text/html')
|
77
79
|
@html5_page = @http.get_page(page.url)
|
78
80
|
end
|
@@ -82,8 +84,8 @@ describe ValidateWebsite::Validator do
|
|
82
84
|
validator = subject.new(@html5_page.doc,
|
83
85
|
@html5_page.body,
|
84
86
|
html5_validator: :nu)
|
85
|
-
validator.valid
|
86
|
-
validator.errors.size.must_equal 3
|
87
|
+
_(validator.valid?).must_equal false
|
88
|
+
_(validator.errors.size).must_equal 3
|
87
89
|
end
|
88
90
|
|
89
91
|
it 'should exclude errors ignored by :ignore option' do
|
@@ -92,8 +94,8 @@ describe ValidateWebsite::Validator do
|
|
92
94
|
@html5_page.body,
|
93
95
|
ignore: ignore,
|
94
96
|
html5_validator: :nu)
|
95
|
-
validator.valid
|
96
|
-
validator.errors.size.must_equal 1
|
97
|
+
_(validator.valid?).must_equal false
|
98
|
+
_(validator.errors.size).must_equal 1
|
97
99
|
end
|
98
100
|
end
|
99
101
|
|
@@ -101,8 +103,8 @@ describe ValidateWebsite::Validator do
|
|
101
103
|
it 'should have an array of errors' do
|
102
104
|
validator = subject.new(@html5_page.doc,
|
103
105
|
@html5_page.body)
|
104
|
-
validator.valid
|
105
|
-
validator.errors.size.must_equal
|
106
|
+
_(validator.valid?).must_equal false
|
107
|
+
_(validator.errors.size).must_equal 3
|
106
108
|
end
|
107
109
|
|
108
110
|
it 'should exclude errors ignored by :ignore option' do
|
@@ -110,8 +112,8 @@ describe ValidateWebsite::Validator do
|
|
110
112
|
validator = subject.new(@html5_page.doc,
|
111
113
|
@html5_page.body,
|
112
114
|
ignore: ignore)
|
113
|
-
validator.valid
|
114
|
-
validator.errors.size.must_equal 2
|
115
|
+
_(validator.valid?).must_equal false
|
116
|
+
_(validator.errors.size).must_equal 2
|
115
117
|
end
|
116
118
|
end
|
117
119
|
end
|
@@ -122,13 +124,13 @@ describe ValidateWebsite::Validator do
|
|
122
124
|
name = 'html4-strict'
|
123
125
|
file = File.join('test', 'data', "#{name}.html")
|
124
126
|
page = FakePage.new(name,
|
125
|
-
body: open(file).read,
|
127
|
+
body: File.open(file).read,
|
126
128
|
content_type: 'text/html')
|
127
129
|
@html4_strict_page = @http.get_page(page.url)
|
128
130
|
validator = subject.new(@html4_strict_page.doc,
|
129
131
|
@html4_strict_page.body)
|
130
132
|
validator.valid?
|
131
|
-
validator.errors.must_equal []
|
133
|
+
_(validator.errors).must_equal []
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|