lazy-check 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4540dba4a1ad89f81bd1bb54e043eb34f25713e4d2ccf42c2641973980354bd
4
- data.tar.gz: c858d4a60f915abf1d48536573f47333b54c6db6aeaaa10bdff05a4c686b2e69
3
+ metadata.gz: 01b26c8325189a7f9eb1fd7267c017fb85462466363d698dc85925292ff77204
4
+ data.tar.gz: c4e0094b36134478cbed092b1a94d00fc7ec89e9439e452ef958c908680e27da
5
5
  SHA512:
6
- metadata.gz: 940d1b4d6923e86683567e14da74632f877bad2666cda026a5804812d96ff2a824978e4c18951fe1edbaff259c534e0f5cc487c7648ee6056cc2fe6f197376b1
7
- data.tar.gz: b36023a7a8711fe75c5df0851ee81ce9f28f23ee52523e7363402c89e7516641b3d39ccefcff3cf3d47c9cb9166e58154bca1b0c952d515744c2677d020ee026
6
+ metadata.gz: 0c5e860db28567e05f96909b080a723e8a7b2c047ad72e53a01f46126db543557beb492f02283b4e17d9328a3790d6e4546e1b81cc502090d5971ca4046dd429
7
+ data.tar.gz: 13e3bb1d81c208c74702f47df3dbcf37b1f0be82b474311e8456c486dc97673fe2f0cc6be676a95b4899d6f0ba73eb0fef16c2cd1c9accd93ed4cd17ca4ad897
data/README-fr.md ADDED
@@ -0,0 +1,150 @@
1
+ # Lazy::Check
2
+
3
+ Ce gem permet de tester de façon paresseuse un site web.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lazy-check'
11
+ require 'lazy/check'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install lazy-check
21
+
22
+ ## Usage
23
+
24
+ ### Pour un test simple (sans recette)
25
+
26
+ Si on a juste du code XML-like à tester, on peut utiliser la méthode `Lazy::Checker.check`.
27
+
28
+ ~~~ruby
29
+ gem 'lazy-check'
30
+ require 'lazy/check'
31
+
32
+ code = "<root><div class="contient">du texte</div></root>"
33
+ check = {tag: 'div.contient', text: "du texte"}
34
+ Lazy::Checker.check(code, check)
35
+ # => Écrit :
36
+ # -------------------------------------
37
+ # Succès 1 Failure 0 Temps ...
38
+ ~~~
39
+
40
+ On peut aussi obtenir les résultats en retour de méthode (c'est un `Lazy::Checker::Reporter`)
41
+
42
+ ~~~ruby
43
+ Lazy::Checker.check(code, check, **{return_result: true})
44
+ # => Reporter
45
+ ~~~
46
+
47
+ > Noter que dans ce cas-là, rien n'est écrit en console.
48
+
49
+ ## Pour un test avec recette
50
+
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
+
53
+ ~~~ruby
54
+ require "lazy-check"
55
+
56
+ checker = Lazy::Checker.new("path/to/recipe.yaml")
57
+ checker.check
58
+ # => Produit le résultat
59
+ ~~~
60
+
61
+ Si la recette se trouve là où le terminal se trouve, il suffit de faire :
62
+
63
+ ~~~ruby
64
+ require "lazy-check"
65
+
66
+ Lazy::Checker.new.check
67
+ ~~~
68
+
69
+ La recette (`recipe.yaml`) définit les vérifications qu'il faut effectuer.
70
+
71
+ ~~~yaml
72
+ ---
73
+ name: "Nom général de la recette"
74
+ base: https://www.mon.domaine.net
75
+ tests:
76
+ - name: "Le premier test"
77
+ url: "" # donc la base
78
+ checks:
79
+ - name: "Existence du DIV#content avec du texte"
80
+ tag: 'div#content'
81
+ empty: false
82
+ - name: "Existence du SPAN#range sans texte"
83
+ tag: 'span#range'
84
+ empty: true
85
+
86
+ - name: "Une redirection"
87
+ url: "redirection.html"
88
+ redirect_to: "https://nouvelle.url.net"
89
+
90
+ - name: "Une page erronée"
91
+ url: "page_inexistante.html"
92
+ response: 404
93
+ ~~~
94
+
95
+ ### Check Properties
96
+
97
+ ~~~yaml
98
+ tag: [String] Le sélector
99
+ count: [Integer] Nombre attendu d'éléments
100
+ empty: [Bool] Si true, doit être vide ou non vide
101
+ direct_child: [Bool] Si true, doit être un enfant direct
102
+ text: [String] Le texte qui doit être contenu
103
+ contains: [String|Array] Ce que doit contenir la page
104
+ min_length: [Integer] La longueur minimum du contenu (text seulement)
105
+ max_length: [Integer] La longueur maximum du contenu (text seulement)
106
+ ~~~
107
+
108
+ ## Exemples
109
+
110
+ Simplement vérifier qu’une page réponde correctement :
111
+
112
+ ~~~yaml
113
+ # recipe.yaml
114
+ ---
115
+ name: "La page existe"
116
+ base: 'https://monsite.net'
117
+ tests:
118
+ - name: "La page index.html existe et répond correctement"
119
+ url: 'index.html'
120
+ response: 200
121
+ ~~~
122
+
123
+ Vérifier qu’une page contient les éléments de base
124
+
125
+ ~~~yaml
126
+ # recipe.yaml
127
+ ---
128
+ name: "Check simple de l'existence des éléments de base"
129
+ base: 'https://monsite.net'
130
+ tests:
131
+ - name: "La page base.html contient les éléments de base"
132
+ url: 'index.html'
133
+ checks:
134
+ - tag: 'header'
135
+ - tag: 'section#body'
136
+ - tag: 'footer'
137
+ ~~~
138
+
139
+
140
+
141
+ ## Development
142
+
143
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
144
+
145
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
146
+
147
+ ## Contributing
148
+
149
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PhilippePerret/lazy-check.
150
+
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Lazy::Check
2
2
 
3
- Ce gem permet de tester de façon paresseuse un site web.
3
+ This gem allows you to lazily test a website.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,7 +8,7 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
10
  gem 'lazy-check'
11
- gem 'lazy/check'
11
+ require 'lazy/check'
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -21,20 +21,20 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- ### Pour un test simple
24
+ ### For a simple test (without a recipe)
25
25
 
26
- Si on a juste du code XML-like à tester, on peut utiliser la méthode `Lazy::Checker.check`.
26
+ If you only have XML-like code to test, you can use the `Lazy::Checker#check` method.
27
27
 
28
28
  ~~~ruby
29
29
  gem 'lazy-check'
30
30
  require 'lazy/check'
31
31
 
32
- code = "<root><div class="contient">du texte</div></root>"
33
- check = {tag: 'div.contient', text: "du texte"}
32
+ code = "<root><div class="contains">some text</div></root>"
33
+ check = {tag: 'div.contains', text: "some text"}
34
34
  Lazy::Checker.check(code, check)
35
- # => Écrit :
35
+ # => Output:
36
36
  # -------------------------------------
37
- # Succès 1 Failure 0 Temps ...
37
+ # Success 1 Failures 0 Duration ...
38
38
  ~~~
39
39
 
40
40
  On peut aussi obtenir les résultats en retour de méthode (c'est un `Lazy::Checker::Reporter`)
@@ -1,4 +1,56 @@
1
1
  ---
2
+ # -- Erreurs de recette --
3
+ 200: |
4
+ The recipe file '%{path}' could not be found.
5
+ 201: |
6
+ The data %{a} is not valid for instantiating a Checker::Url. It should
7
+ be either a (valid) URL or valid HTML code.
8
+ 202: |
9
+ The recipe file does not contain any data.
10
+ 203: |
11
+ The recipe data should be a table (Hash), not a %{c}.
12
+ 204: |
13
+ The recipe should define the key :tests. It only defines the keys %{ks}.
14
+ 205: |
15
+ The :tests data should be an Array, not a %{c}.
16
+ 206: |
17
+ The recipe should define its name with the key :name.
18
+
19
+ # -- Errors in test definition. --
20
+
21
+ 300: |
22
+ The test data should be a Hash table, not a %{c}.
23
+ 301: |
24
+ The test table should define the :url property, which is the page to reach.
25
+ I only find the %{ks} properties.
26
+ 302: |
27
+ The provided URL (%{u}) is not valid: %{e}.
28
+ 303: |
29
+ it must be defined, not nil.
30
+ 304: |
31
+ it must be a string, not a %{c}.
32
+ 305: |
33
+ it must start with 'http' or 'https' necessarily.
34
+ 306: |
35
+ it should not contain any spaces.
36
+ 307: |
37
+ A test must define its name (in :name); it only defines the keys %{ks}.
38
+ 308: |
39
+ A test must define the checks to perform in a property called, specifically,
40
+ :checks. The test only defines the %{ks} properties.
41
+ 309: |
42
+ The checks to be performed for the test (:checks) should be a list (Array),
43
+ not a %{c}.
44
+ 310: |
45
+ The redirection %{a} should be a string, not a %{c}.
46
+ 311: |
47
+ The redirection %{a} should start with 'http[s]'.
48
+ 312: |
49
+ To test the HTTP response, you must provide the expected status code, which should
50
+ be an Integer. However, %{a} is a %{c}.
51
+ For example, you can use: 404.
52
+ 800: |
53
+ -- UNUSED --
2
54
  1000: |
3
55
  Lazy::Checker::CheckCase instanciation requires a Lazy::Checker::Url (first argument).
4
56
  Actual value is %{a}::%{c}.
@@ -11,3 +63,75 @@
11
63
  1003: |
12
64
  :tag value of the CheckCase data should define at least a id (tagName#id) or a css
13
65
  class (tagName.css_class). '%{a}' defines neither.
66
+ 1004: |
67
+ In the :tag data, :count (%{a}) should be a number, not a %{c}.
68
+ 2000: |
69
+ The definition of :contains is incorrect. It should be a table (defining at
70
+ least :tag), a string (text to be contained or a tag with an identifier and/or
71
+ CSS class), or a list of these elements. The class of the element, in any case,
72
+ cannot be %{c}.
73
+
74
+ # --- Errors in page check. ---
75
+
76
+ 4999: |
77
+ No %{tag} element was found when %{e} were expected.
78
+ 5000: |
79
+ Wrong count. We expected %{e} %{tag} elements, but found %{a} on the page.
80
+ 5001: |
81
+ The content of %{tag} should be empty, but it contains the text
82
+ "%{a}".
83
+ 5002: |
84
+ The content of %{tag} should not be empty, but it is.
85
+ 5003: |
86
+ The content of %{tag} should not contain any text, but it
87
+ contains %{a}.
88
+ 5004: |
89
+ The content of %{tag} should contain text, but it doesn't display any.
90
+ 5010: |
91
+ We should find %{tag} containing %{e}. The following issues were
92
+ encountered: %{a}.
93
+ 5011: |
94
+ We should find %{tag} containing the text %{e}.
95
+ 5020: |
96
+ should contain the string %{e}
97
+ 5021: |
98
+ should contain the tag defined by %{e}
99
+ 5030: |
100
+ should define the attributes
101
+ 5031: |
102
+ missing or unequal attributes: %{e}.
103
+ 5032: |
104
+ the content is not long enough. It should be at least %{e} characters long,
105
+ but it is %{a} characters long.
106
+ 5033: |
107
+ the content is too long. It should be less than %{e} characters, but it
108
+ is %{a} characters long.
109
+
110
+ 5500: |
111
+ The URL is not redirected. It should have been redirected to
112
+ %{e}.
113
+ 5501: |
114
+ The URL is redirected to the wrong address. It should have been redirected to: %{e}.
115
+ It is redirected to: %{a}.
116
+ 5502: |
117
+ The expected HTTP Response is not correct...
118
+ We were expecting the response: %{e}
119
+ We received the response: %{a}
120
+ 5503: |
121
+ Error 404. The page %{e} could not be found.
122
+ 6000: |
123
+ The first argument of Lazy::Checker.check must be valid XML code.
124
+ However, %{se}.
125
+ 6001: |
126
+ %{a} is not a String; it's a %{c}.
127
+ 6002: |
128
+ a valid XML code should be wrapped in a root node. This is not the case
129
+ for %{a}.
130
+ 6003: |
131
+ the data is null (nil).
132
+ 6010: |
133
+ The second argument of Lazy::Checker.check must be a valid Hash table, containing
134
+ the correct keys: %{se}.
135
+ 6011: |
136
+ %{a} is not a Hash; it's a %{c}.
137
+
@@ -0,0 +1,23 @@
1
+ ---
2
+ # -- Termes de messages --
3
+ 10: 'count '
4
+ 11: 'length '
5
+ 12: 'min length '
6
+ 13: 'max length '
7
+ 14: 'empty'
8
+ 15: 'not empty'
9
+ 16: 'containing'
10
+ 17: 'containing the string'
11
+ 20: 'only as direct child'
12
+ 21: 'with attributes'
13
+
14
+ Success: 'Success'
15
+ Failures: 'Failures'
16
+ Duration: 'Duration'
17
+ PleaseWait: 'Please wait…'
18
+
19
+ # -- Les messages de retour des checks --
20
+
21
+ 4999: |
22
+ %{tag} tag found with expected data:
23
+ %{f_data}
@@ -11,6 +11,11 @@
11
11
  20: 'seulement parmi les enfants directs'
12
12
  21: 'avec les attributs'
13
13
 
14
+ Success: 'Succès'
15
+ Failures: 'Échecs'
16
+ Duration: 'Durée'
17
+ PleaseWait: 'Merci de patienter…'
18
+
14
19
  # -- Les messages de retour des checks --
15
20
 
16
21
  4999: |
@@ -29,7 +29,7 @@ class Checker
29
29
  display_list_resultats(success = false)
30
30
  end
31
31
  color = nombre_erreurs > 0 ? :red : :vert
32
- msg = "Success #{@successs.count} Failures #{@failures.count} Temps #{formated_duree}"
32
+ msg = "#{MESSAGES[:Success]} #{@successs.count} #{MESSAGES[:Failures]} #{@failures.count} #{MESSAGES[:Duration]} #{formated_duree}"
33
33
  puts "-" * msg.length
34
34
  puts msg.send(color)
35
35
  end
@@ -46,7 +46,7 @@ class Checker
46
46
  methode = success ? :message : :errors
47
47
  color = success ? :vert : :red
48
48
  liste = success ? @successs : @failures
49
- prefix = success ? 'SUCCESS' : 'FAILURE'
49
+ prefix = success ? '👍' : '👎'
50
50
 
51
51
  max_index = liste.count + 1
52
52
  max_len_index = "[#{prefix} #{max_index}] ".length
@@ -61,7 +61,7 @@ class Checker
61
61
  clear unless debug?
62
62
  puts "\n\n"
63
63
  puts "#{checker.name}".jaune
64
- puts "Merci de patienter…".bleu
64
+ puts MESSAGES[:PleaseWait].bleu
65
65
  @start_time = Time.now
66
66
  @successs = []
67
67
  @failures = []
@@ -1,5 +1,5 @@
1
1
  module Lazy
2
2
  module Check
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PhilippePerret
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-29 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -80,6 +80,7 @@ files:
80
80
  - Gemfile
81
81
  - Gemfile.lock
82
82
  - Notes-developper.md
83
+ - README-fr.md
83
84
  - README.md
84
85
  - Rakefile
85
86
  - bin/console
@@ -96,6 +97,7 @@ files:
96
97
  - lib/lazy/check/checker_url.rb
97
98
  - lib/lazy/check/constants.rb
98
99
  - lib/lazy/check/locales/en/errors.yaml
100
+ - lib/lazy/check/locales/en/messages.yaml
99
101
  - lib/lazy/check/locales/fr/errors.yaml
100
102
  - lib/lazy/check/locales/fr/messages.yaml
101
103
  - lib/lazy/check/reporter.rb