lazy-check 1.2.1 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README-fr.md +20 -12
- data/README.md +46 -38
- data/lib/lazy/check/Nokogiri_extension.rb +4 -4
- data/lib/lazy/check/checker.rb +9 -6
- data/lib/lazy/check/checker_code.rb +11 -1
- data/lib/lazy/check/locales/en/messages.yaml +1 -0
- data/lib/lazy/check/locales/fr/messages.yaml +1 -0
- data/lib/lazy/check/reporter.rb +6 -4
- data/lib/lazy/check/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83a4373e41aeeabf3eb57866324069a1134ee606065556cbf17ed78b10de5cff
|
4
|
+
data.tar.gz: 6f7448fe3242c1dcd5189e50e92f2aeead83fe6b6da8dd974b9974c1e14d14a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bec5356e9df9a71fb5abe4e8db50c6990551ba1dd360ea7d93511a424cbb7f90c7aeb53aa18988dc0138b2b8f5747c4e6dbdb19c4b1c60d38054f687c233d83
|
7
|
+
data.tar.gz: 0b9b2cff492148a86222f32e01f1ef2b7ba70deafeca6637fa69fdb06e82740dd6a890342565fcfdb2d1a7337ad8be1007d5c8b24df49a4e09753c5746e5b4fb
|
data/README-fr.md
CHANGED
@@ -37,7 +37,7 @@ Lazy::Checker.check(code, check)
|
|
37
37
|
# Succès 1 Failure 0 Temps ...
|
38
38
|
~~~
|
39
39
|
|
40
|
-
On peut aussi obtenir les résultats en retour de méthode (c'est un `Lazy::Checker::Reporter`)
|
40
|
+
On peut aussi obtenir les résultats en retour de méthode (c'est un `Lazy::Checker::Reporter`).
|
41
41
|
|
42
42
|
~~~ruby
|
43
43
|
Lazy::Checker.check(code, check, **{return_result: true})
|
@@ -51,7 +51,7 @@ Lazy::Checker.check(code, check, **{return_result: true})
|
|
51
51
|
Une « recette » est un fichier `YAML` qui définit l'url d'une page internet, ainsi que les checks à effectuer dessus. Cf. ci-dessous.
|
52
52
|
|
53
53
|
~~~ruby
|
54
|
-
require "lazy
|
54
|
+
require "lazy/check"
|
55
55
|
|
56
56
|
checker = Lazy::Checker.new("path/to/recipe.yaml")
|
57
57
|
checker.check
|
@@ -61,7 +61,7 @@ checker.check
|
|
61
61
|
Si la recette se trouve là où le terminal se trouve, il suffit de faire :
|
62
62
|
|
63
63
|
~~~ruby
|
64
|
-
require "lazy
|
64
|
+
require "lazy/check"
|
65
65
|
|
66
66
|
Lazy::Checker.new.check
|
67
67
|
~~~
|
@@ -83,21 +83,23 @@ tests:
|
|
83
83
|
tag: 'span#range'
|
84
84
|
empty: true
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
- name: "Une redirection"
|
87
|
+
url: "redirection.html"
|
88
|
+
redirect_to: "https://nouvelle.url.net"
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
- name: "Une page erronée"
|
91
|
+
url: "page_inexistante.html"
|
92
|
+
response: 404
|
93
93
|
~~~
|
94
94
|
|
95
95
|
### Check Properties
|
96
96
|
|
97
|
+
Les "checks" ci-dessus peuvent définir les propriétés suivantes :
|
98
|
+
|
97
99
|
~~~yaml
|
98
100
|
tag: [String] Le sélector
|
99
101
|
count: [Integer] Nombre attendu d'éléments
|
100
|
-
empty: [Bool] Si true, doit être vide
|
102
|
+
empty: [Bool] Si true, doit être vide, si false, non vide
|
101
103
|
direct_child: [Bool] Si true, doit être un enfant direct
|
102
104
|
text: [String] Le texte qui doit être contenu
|
103
105
|
contains: [String|Array] Ce que doit contenir la page
|
@@ -120,7 +122,7 @@ tests:
|
|
120
122
|
response: 200
|
121
123
|
~~~
|
122
124
|
|
123
|
-
Vérifier qu’une page contient les éléments de base
|
125
|
+
Vérifier qu’une page contient les éléments de base :
|
124
126
|
|
125
127
|
~~~yaml
|
126
128
|
# recipe.yaml
|
@@ -128,7 +130,7 @@ Vérifier qu’une page contient les éléments de base
|
|
128
130
|
name: "Check simple de l'existence des éléments de base"
|
129
131
|
base: 'https://monsite.net'
|
130
132
|
tests:
|
131
|
-
- name: "La page
|
133
|
+
- name: "La page index.html contient les éléments de base"
|
132
134
|
url: 'index.html'
|
133
135
|
checks:
|
134
136
|
- tag: 'header'
|
@@ -136,7 +138,13 @@ tests:
|
|
136
138
|
- tag: 'footer'
|
137
139
|
~~~
|
138
140
|
|
141
|
+
## Tester le gem
|
142
|
+
|
143
|
+
Lancer les tests avec :
|
139
144
|
|
145
|
+
~~~
|
146
|
+
rake test
|
147
|
+
~~~
|
140
148
|
|
141
149
|
## Development
|
142
150
|
|
data/README.md
CHANGED
@@ -37,98 +37,100 @@ Lazy::Checker.check(code, check)
|
|
37
37
|
# Success 1 Failures 0 Duration ...
|
38
38
|
~~~
|
39
39
|
|
40
|
-
|
40
|
+
You can also obtain the results in method return (this is a `Lazy::Checker::Reporter`).
|
41
41
|
|
42
42
|
~~~ruby
|
43
43
|
Lazy::Checker.check(code, check, **{return_result: true})
|
44
44
|
# => Reporter
|
45
45
|
~~~
|
46
46
|
|
47
|
-
>
|
47
|
+
> Note that in this case, nothing is written in the console.
|
48
48
|
|
49
|
-
##
|
49
|
+
## For a test with a recipe
|
50
50
|
|
51
|
-
|
51
|
+
A "recipe" is a `YAML` file that defines the url of a web page, and the checks to be performed on it. See below.
|
52
52
|
|
53
53
|
~~~ruby
|
54
|
-
require "lazy
|
54
|
+
require "lazy/check"
|
55
55
|
|
56
56
|
checker = Lazy::Checker.new("path/to/recipe.yaml")
|
57
57
|
checker.check
|
58
|
-
# =>
|
58
|
+
# => Produces the result
|
59
59
|
~~~
|
60
60
|
|
61
|
-
|
61
|
+
If the recipe is located where the terminal is, simply do:
|
62
62
|
|
63
63
|
~~~ruby
|
64
|
-
require "lazy
|
64
|
+
require "lazy/check"
|
65
65
|
|
66
66
|
Lazy::Checker.new.check
|
67
67
|
~~~
|
68
68
|
|
69
|
-
|
69
|
+
The recipe (`recipe.yaml`) defines the checks to be performed.
|
70
70
|
|
71
71
|
~~~yaml
|
72
72
|
---
|
73
|
-
name: "
|
74
|
-
base: https://www.
|
73
|
+
name: "Name for this recipe"
|
74
|
+
base: https://www.my.domain.net
|
75
75
|
tests:
|
76
|
-
- name: "
|
77
|
-
url: "" #
|
76
|
+
- name: "My first test"
|
77
|
+
url: "" # so the base
|
78
78
|
checks:
|
79
|
-
- name: "Existence
|
79
|
+
- name: "Existence of DIV#content with text"
|
80
80
|
tag: 'div#content'
|
81
81
|
empty: false
|
82
|
-
- name: "Existence
|
82
|
+
- name: "Existence of SPAN#range without text"
|
83
83
|
tag: 'span#range'
|
84
84
|
empty: true
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
- name: "A redirection"
|
87
|
+
url: "redirection.html"
|
88
|
+
redirect_to: "https://new.url.net"
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
- name: "A wrong page"
|
91
|
+
url: "page_unfound.html"
|
92
|
+
response: 404
|
93
93
|
~~~
|
94
94
|
|
95
95
|
### Check Properties
|
96
96
|
|
97
|
+
The above "checks" can define the following properties:
|
98
|
+
|
97
99
|
~~~yaml
|
98
|
-
tag: [String]
|
99
|
-
count: [Integer]
|
100
|
-
empty: [Bool]
|
101
|
-
direct_child: [Bool]
|
102
|
-
text: [String]
|
103
|
-
contains: [String|Array]
|
104
|
-
min_length: [Integer]
|
105
|
-
max_length: [Integer]
|
100
|
+
tag: [String] The selector
|
101
|
+
count: [Integer] Expected number of elements
|
102
|
+
empty: [Bool] If true, must be empty, if false, must be non-empty
|
103
|
+
direct_child: [Bool] If true, must be a direct child
|
104
|
+
text: [String] The text that must be contained
|
105
|
+
contains: [String|Array] What the page should contain
|
106
|
+
min_length: [Integer] Minimum content length (text only)
|
107
|
+
max_length: [Integer] Maximum content length (text only)
|
106
108
|
~~~
|
107
109
|
|
108
|
-
##
|
110
|
+
## Examples
|
109
111
|
|
110
|
-
|
112
|
+
Simply check that a page responds correctly:
|
111
113
|
|
112
114
|
~~~yaml
|
113
115
|
# recipe.yaml
|
114
116
|
---
|
115
|
-
name: "
|
116
|
-
base: 'https://
|
117
|
+
name: "Page exists"
|
118
|
+
base: 'https://mywebsite.net'
|
117
119
|
tests:
|
118
|
-
- name: "
|
120
|
+
- name: "The index.html page exists and responds correctly"
|
119
121
|
url: 'index.html'
|
120
122
|
response: 200
|
121
123
|
~~~
|
122
124
|
|
123
|
-
|
125
|
+
Check that a page contains the basic elements.
|
124
126
|
|
125
127
|
~~~yaml
|
126
128
|
# recipe.yaml
|
127
129
|
---
|
128
|
-
name: "
|
129
|
-
base: 'https://
|
130
|
+
name: "Simple check on the existence of basic elements"
|
131
|
+
base: 'https://mywebsite.net'
|
130
132
|
tests:
|
131
|
-
- name: "
|
133
|
+
- name: "The index.html page contains the basic elements"
|
132
134
|
url: 'index.html'
|
133
135
|
checks:
|
134
136
|
- tag: 'header'
|
@@ -136,7 +138,13 @@ tests:
|
|
136
138
|
- tag: 'footer'
|
137
139
|
~~~
|
138
140
|
|
141
|
+
## Tests
|
142
|
+
|
143
|
+
Run the tests:
|
139
144
|
|
145
|
+
~~~
|
146
|
+
rake test
|
147
|
+
~~~
|
140
148
|
|
141
149
|
## Development
|
142
150
|
|
@@ -16,7 +16,7 @@ module Nokogiri
|
|
16
16
|
|
17
17
|
# @return true si le node est vraiment vide
|
18
18
|
def empty?
|
19
|
-
not(children?) && content.empty?
|
19
|
+
not(children?) && content.strip.empty?
|
20
20
|
end
|
21
21
|
|
22
22
|
def children?
|
@@ -24,11 +24,11 @@ module Nokogiri
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def has_text?
|
27
|
-
not(text.empty?)
|
27
|
+
not(text.strip.empty?)
|
28
28
|
end
|
29
29
|
|
30
30
|
def has_no_text?
|
31
|
-
text.empty?
|
31
|
+
text.strip.empty?
|
32
32
|
end
|
33
33
|
|
34
34
|
# Test du contenu
|
@@ -141,7 +141,7 @@ module Nokogiri
|
|
141
141
|
|
142
142
|
# @return [Integer] La longueur du texte
|
143
143
|
def length
|
144
|
-
@length ||= text.length
|
144
|
+
@length ||= text.strip.length
|
145
145
|
end
|
146
146
|
end #/class XML::Element
|
147
147
|
end #/module Nokogiri
|
data/lib/lazy/check/checker.rb
CHANGED
@@ -7,6 +7,8 @@ class Checker
|
|
7
7
|
|
8
8
|
attr_reader :reporter
|
9
9
|
|
10
|
+
attr_reader :options
|
11
|
+
|
10
12
|
def initialize(recipe_path = nil)
|
11
13
|
recipe_path ||= File.expand_path('.', 'recipe.yaml')
|
12
14
|
File.exist?(recipe_path) || raise(ERRORS[200] % {path: recipe_path})
|
@@ -24,6 +26,7 @@ class Checker
|
|
24
26
|
# La méthode (silencieuse) qui produit le check
|
25
27
|
# ("silencieuse" parce qu'elle ne produit que des raises)
|
26
28
|
def proceed_check(**options)
|
29
|
+
@options = options
|
27
30
|
@reporter = Reporter.new(self)
|
28
31
|
@reporter.start
|
29
32
|
recipe[:tests].collect do |dtest|
|
@@ -32,10 +35,10 @@ class Checker
|
|
32
35
|
test.check(**options)
|
33
36
|
end
|
34
37
|
@reporter.end
|
35
|
-
if
|
38
|
+
if no_output?
|
36
39
|
return @reporter
|
37
40
|
else
|
38
|
-
@reporter.display
|
41
|
+
@reporter.display
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
@@ -45,6 +48,10 @@ class Checker
|
|
45
48
|
not(base.nil?)
|
46
49
|
end
|
47
50
|
|
51
|
+
def no_output?
|
52
|
+
options[:return_result] === true
|
53
|
+
end
|
54
|
+
|
48
55
|
def recipe_valid?
|
49
56
|
not(recipe.nil?) || raise(RecipeError, ERRORS[202])
|
50
57
|
recipe.is_a?(Hash) || raise(RecipeError, ERRORS[203] % {c: recipe.class.name})
|
@@ -55,10 +62,6 @@ class Checker
|
|
55
62
|
recipe[:tests].is_a?(Array) || raise(RecipeError, ERRORS[205] % {c: recipe[:tests].class.name})
|
56
63
|
end
|
57
64
|
|
58
|
-
def no_output?
|
59
|
-
@options[:output] === false
|
60
|
-
end
|
61
|
-
|
62
65
|
# --- Données ---
|
63
66
|
|
64
67
|
def name
|
@@ -33,7 +33,6 @@ class Checker
|
|
33
33
|
checker.check_against(@data_check, **options)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
36
|
private
|
38
37
|
|
39
38
|
# Méthode qui vérifie la conformité de la donnée
|
@@ -80,6 +79,8 @@ class Checker
|
|
80
79
|
# de test)
|
81
80
|
attr_reader :report
|
82
81
|
|
82
|
+
attr_reader :options
|
83
|
+
|
83
84
|
def initialize(xml_code)
|
84
85
|
@xml_code = xml_code
|
85
86
|
@urler = Checker::Url.new(xml_code)
|
@@ -91,6 +92,7 @@ class Checker
|
|
91
92
|
# :return_result Si true, on retourne les données au lieu de les afficher
|
92
93
|
#
|
93
94
|
def check_against(data_check, **options)
|
95
|
+
@options = options
|
94
96
|
@report = Reporter.new(self)
|
95
97
|
@report.start
|
96
98
|
check_case = Checker::CheckCase.new(urler, data_check, @report)
|
@@ -103,6 +105,14 @@ class Checker
|
|
103
105
|
end
|
104
106
|
end
|
105
107
|
|
108
|
+
def name
|
109
|
+
MESSAGES[:CodeToTest]
|
110
|
+
end
|
111
|
+
|
112
|
+
def no_output?
|
113
|
+
options[:return_result] === true
|
114
|
+
end
|
115
|
+
|
106
116
|
end #/class Code
|
107
117
|
end #/class Checker
|
108
118
|
end #/module Lazy
|
data/lib/lazy/check/reporter.rb
CHANGED
@@ -58,10 +58,12 @@ class Checker
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def start
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
unless checker.no_output?
|
62
|
+
clear unless debug?
|
63
|
+
puts "\n\n"
|
64
|
+
puts "#{checker.name}".jaune
|
65
|
+
puts MESSAGES[:PleaseWait].bleu
|
66
|
+
end
|
65
67
|
@start_time = Time.now
|
66
68
|
@successs = []
|
67
69
|
@failures = []
|
data/lib/lazy/check/version.rb
CHANGED