mumuki-text-runner 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/checker.rb +36 -4
- data/lib/comparators/comparator.rb +26 -0
- data/lib/comparators/contain_comparator.rb +12 -0
- data/lib/comparators/equality_comparator.rb +12 -0
- data/lib/comparators/regexp_comparator.rb +13 -0
- data/lib/comparators/valid_ip_comparator.rb +14 -0
- data/lib/locales/en.yml +9 -0
- data/lib/locales/es.yml +9 -0
- data/lib/metadata_hook.rb +7 -5
- data/lib/options/ignore_case.rb +3 -5
- data/lib/options/ignore_whitespace.rb +3 -5
- data/lib/test_hook.rb +19 -1
- data/lib/text_runner.rb +3 -8
- data/lib/version_hook.rb +3 -0
- metadata +45 -24
- data/lib/comparers/equality_comparer.rb +0 -29
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZGVhMjUxYWNjYmQwZTAyZGMwYzcxZjM4MGE0MzM1NzQ2ZGQ3M2Q4ZA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43678016289325cc51c7f82a3c3696d8113641032b2c1b97f4a68ce4835bc3c6
|
4
|
+
data.tar.gz: b237d0b7ec9d0fe5e8dc110accf493fbd17ac35d55bb3f2e14856b1f277922f9
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZWVjNTlmNWM0YjIzMzMwMzlkYmJhM2QwY2RkOTgwNGQ3OWU3ZTVkOTIxYzE1
|
11
|
-
NDRmNDNjOTkzMDQ2MjNjY2RhNTZjMGQ2YWZhNGQ4OTFiMDZiY2Q=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzBjNTIxMzEzZjBiZmVlODI4ZjlmYTg5ODdjMjlmYmY2Y2E0OWMzODI4Y2U3
|
14
|
-
YmQzMTM2NWExYzFhOGIzY2FkODYyZjcyM2I2YThiMWFkNzk0NmJhYTY1NWRk
|
15
|
-
YWE2YzY5MDk1MTk4ZDM0OTM1NzFkYTlkZWYxMzYzMjFkODViYzg=
|
6
|
+
metadata.gz: 134703fbbf89aa87c224e1efa93752e7f7681b82586ce56325b31cd342ac72fda98ba38136a747b54e9e635068e372f0236fe837caa569f6b1072048719e4371
|
7
|
+
data.tar.gz: a224bb63533f2f352c4a4be7cfa51ea9030a6fe7c3d0258bfb15a63f711678994fa60007207ee1823960c0dc1b60b9ccda5ac0d339c395400de98abc42e02f2e
|
data/lib/checker.rb
CHANGED
@@ -1,7 +1,39 @@
|
|
1
1
|
class TextChecker < Mumukit::Metatest::Checker
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
require_relative './comparators/comparator'
|
3
|
+
require_relative './comparators/equality_comparator'
|
4
|
+
require_relative './comparators/contain_comparator'
|
5
|
+
require_relative './comparators/regexp_comparator'
|
6
|
+
require_relative './comparators/valid_ip_comparator'
|
7
|
+
|
8
|
+
require_relative './options/ignore_whitespace'
|
9
|
+
require_relative './options/ignore_case'
|
10
|
+
|
11
|
+
COMPARATORS = {
|
12
|
+
match: TextChecker::RegexpComparator,
|
13
|
+
equal: TextChecker::EqualityComparator,
|
14
|
+
contain: TextChecker::ContainComparator,
|
15
|
+
valid_ip: TextChecker::ValidIpComparator
|
16
|
+
}
|
17
|
+
|
18
|
+
def check_assertion(key, input, config, example)
|
19
|
+
if key == :keys
|
20
|
+
check_keys input, config, example
|
21
|
+
else
|
22
|
+
check_comparators key, input, config
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_comparators(key, input, config)
|
27
|
+
COMPARATORS[key]
|
28
|
+
.new(config.is_a?(Hash) ? config : {expected: config})
|
29
|
+
.compare(input[:source])
|
30
|
+
.try { |error| fail error }
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_keys(input, config, example)
|
34
|
+
source_hash = YAML.load(input[:source]).with_indifferent_access
|
35
|
+
config.each do |subkey, subconfig|
|
36
|
+
check_assertions({source: source_hash[subkey]}, subconfig, example)
|
37
|
+
end
|
6
38
|
end
|
7
39
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class TextChecker::Comparator
|
2
|
+
def initialize(config = {})
|
3
|
+
@config = config
|
4
|
+
end
|
5
|
+
|
6
|
+
def compare(source)
|
7
|
+
@config[:error] || error_message(source) unless success?(transform(source))
|
8
|
+
end
|
9
|
+
|
10
|
+
def expected
|
11
|
+
transform @config[:expected]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def modifiers
|
17
|
+
modifiers = []
|
18
|
+
modifiers << TextChecker::IgnoreWhitespace if @config[:ignore_whitespace]
|
19
|
+
modifiers << TextChecker::IgnoreCase if @config[:ignore_case]
|
20
|
+
modifiers
|
21
|
+
end
|
22
|
+
|
23
|
+
def transform(source)
|
24
|
+
modifiers.inject(source) { |text, modifier| modifier.apply(text) }
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class TextChecker::ValidIpComparator < TextChecker::Comparator
|
2
|
+
|
3
|
+
def success?(source)
|
4
|
+
!!REGEXP.match(source)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
REGEXP = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i
|
10
|
+
|
11
|
+
def error_message(source)
|
12
|
+
I18n.t 'valid_ip.failure', actual: source
|
13
|
+
end
|
14
|
+
end
|
data/lib/locales/en.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
en:
|
2
|
+
equality:
|
3
|
+
failure: '**%{actual}** is not the right value.'
|
4
|
+
contain:
|
5
|
+
failure: '**%{actual}** does not contain the right value.'
|
6
|
+
expression:
|
7
|
+
failure: '**%{actual}** does not match the expected expression.'
|
8
|
+
valid_ip:
|
9
|
+
failure: '**%{actual}** is not a valid IP address.'
|
data/lib/locales/es.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
es:
|
2
|
+
equality:
|
3
|
+
failure: '**%{actual}** no es el valor correcto.'
|
4
|
+
contain:
|
5
|
+
failure: '**%{actual}** no contiene el valor correcto.'
|
6
|
+
expression:
|
7
|
+
failure: '**%{actual}** no coincide con la expresión correcta.'
|
8
|
+
valid_ip:
|
9
|
+
failure: '**%{actual}** no es una dirección IP válida.'
|
data/lib/metadata_hook.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
class TextMetadataHook < Mumukit::Hook
|
2
2
|
def metadata
|
3
|
-
{
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
{
|
4
|
+
language: {
|
5
|
+
name: 'text',
|
6
|
+
icon: { type: 'devicon', name: 'code' },
|
7
|
+
extension: 'txt',
|
8
|
+
},
|
7
9
|
test_framework: {
|
8
10
|
name: 'text',
|
9
11
|
test_extension: 'yml'
|
10
12
|
}
|
11
|
-
}
|
13
|
+
}
|
12
14
|
end
|
13
15
|
end
|
data/lib/options/ignore_case.rb
CHANGED
data/lib/test_hook.rb
CHANGED
@@ -17,6 +17,24 @@ class TextTestHook < Mumukit::Hook
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def parse_test(tests)
|
20
|
-
YAML.load(tests)
|
20
|
+
parsed_test = YAML.load(tests)
|
21
|
+
if parsed_test.is_a? Array
|
22
|
+
parse_multi_scenario_test(parsed_test)
|
23
|
+
else
|
24
|
+
parse_single_scenario_test(parsed_test)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_single_scenario_test(parsed_test)
|
29
|
+
[{ name: 'test',
|
30
|
+
postconditions: { equal: {
|
31
|
+
expected: parsed_test['equal'],
|
32
|
+
ignore_case: parsed_test['ignore_case'].present?,
|
33
|
+
ignore_whitespace: parsed_test['ignore_whitespace'].present? } }
|
34
|
+
}]
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_multi_scenario_test(parsed_test)
|
38
|
+
parsed_test.map { |example| example.deep_symbolize_keys }
|
21
39
|
end
|
22
40
|
end
|
data/lib/text_runner.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'mumukit'
|
2
2
|
require 'yaml'
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
I18n.load_translations_path File.join(__dir__, 'locales', '*.yml')
|
5
5
|
|
6
6
|
Mumukit.runner_name = 'text'
|
7
7
|
Mumukit.configure do |config|
|
8
8
|
config.content_type = 'markdown'
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
require_relative './version_hook'
|
13
12
|
require_relative './metadata_hook'
|
14
13
|
require_relative './test_hook'
|
15
14
|
|
16
15
|
require_relative './checker'
|
17
|
-
|
18
|
-
require_relative './comparers/equality_comparer'
|
19
|
-
require_relative './options/ignore_whitespace'
|
20
|
-
require_relative './options/ignore_case'
|
data/lib/version_hook.rb
ADDED
metadata
CHANGED
@@ -1,99 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-text-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.27'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.27'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: codeclimate-test-reporter
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: mumukit-bridge
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- - ~>
|
101
|
+
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '1
|
103
|
+
version: '3.1'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- - ~>
|
108
|
+
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1
|
110
|
+
version: '3.1'
|
97
111
|
description:
|
98
112
|
email:
|
99
113
|
- franco@mumuki.org
|
@@ -102,12 +116,19 @@ extensions: []
|
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
118
|
- lib/checker.rb
|
105
|
-
- lib/
|
119
|
+
- lib/comparators/comparator.rb
|
120
|
+
- lib/comparators/contain_comparator.rb
|
121
|
+
- lib/comparators/equality_comparator.rb
|
122
|
+
- lib/comparators/regexp_comparator.rb
|
123
|
+
- lib/comparators/valid_ip_comparator.rb
|
124
|
+
- lib/locales/en.yml
|
125
|
+
- lib/locales/es.yml
|
106
126
|
- lib/metadata_hook.rb
|
107
127
|
- lib/options/ignore_case.rb
|
108
128
|
- lib/options/ignore_whitespace.rb
|
109
129
|
- lib/test_hook.rb
|
110
130
|
- lib/text_runner.rb
|
131
|
+
- lib/version_hook.rb
|
111
132
|
homepage: http://github.com/mumuki/mumuki-text-server
|
112
133
|
licenses:
|
113
134
|
- MIT
|
@@ -118,17 +139,17 @@ require_paths:
|
|
118
139
|
- lib
|
119
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
141
|
requirements:
|
121
|
-
- -
|
142
|
+
- - ">="
|
122
143
|
- !ruby/object:Gem::Version
|
123
144
|
version: '0'
|
124
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
146
|
requirements:
|
126
|
-
- -
|
147
|
+
- - ">="
|
127
148
|
- !ruby/object:Gem::Version
|
128
149
|
version: '0'
|
129
150
|
requirements: []
|
130
151
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.7.7
|
132
153
|
signing_key:
|
133
154
|
specification_version: 4
|
134
155
|
summary: Text Runner for Mumuki
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class EqualityComparer
|
2
|
-
def initialize(config)
|
3
|
-
opts = config
|
4
|
-
opts = { expected: config } unless config.is_a? Hash
|
5
|
-
@expected = opts[:expected]
|
6
|
-
parse_options(opts)
|
7
|
-
end
|
8
|
-
|
9
|
-
def satisfies?(source)
|
10
|
-
@actual = transform(source)
|
11
|
-
@actual == @expected
|
12
|
-
end
|
13
|
-
|
14
|
-
def locale_error_message
|
15
|
-
I18n.t 'equality.failure', actual: @actual
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def transform(source)
|
21
|
-
@modifiers.inject(source) { |text, modifier| modifier.apply(text) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def parse_options(config)
|
25
|
-
@modifiers = []
|
26
|
-
@modifiers << IgnoreWhitespace if config[:ignore_whitespace]
|
27
|
-
@modifiers << IgnoreCase if config[:ignore_case]
|
28
|
-
end
|
29
|
-
end
|