mumuki-text-runner 1.2.1 → 1.3.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: ff637b59a63ae832dbb1707f9ca1c5fd43a1df4a70531d307626449007e59e1c
4
- data.tar.gz: a936a8b9382eb3219615f006fd41b7c2c551b33a5f220bdf087faf6fb8b94770
3
+ metadata.gz: b2b935fa7c9c7cccead52aa65543db209da093b16779b51944ccf4f5053412d5
4
+ data.tar.gz: 14ef6d6d43802dcd76008c27d5275452b09b5c668454163fecec74fe7c90304e
5
5
  SHA512:
6
- metadata.gz: 4ac21ef25b3fb829eb341bde542388285436dccb5f24f99a541579ccf78528ced3d45b2c037124df368fe51d1bdaa018885ea38b32d05871860dda3f3fa35259
7
- data.tar.gz: edb1488843f13aa4046ed7d695425067a1069d965119e80cea903da2ca6c0c64e88ba75263af341e656fd975cacf8fac346fb8f5f801b4faed1cc1f7aaedce63
6
+ metadata.gz: badaa8753e28b572c4adf18559c83f0f1a0ba4797397aa38bd525374be68022771a716c9c09565430ffee2695ee9f3543d2b98ebb46d28d2b3f7384cdb2b146e
7
+ data.tar.gz: 39c00537548e07b45e900519ff0b5e784a8baa34fd9c0055a2d5b0aac2a6d513ffc8f93470621fd042486034ea37c24e130729a1663c1362a91e5dbcb1286d51
data/lib/checker.rb CHANGED
@@ -1,17 +1,39 @@
1
1
  class TextChecker < Mumukit::Metatest::Checker
2
- def self.compare(relation_hash)
3
- raise 'Invalid hash arity' if relation_hash.size != 1
4
- type = relation_hash.keys.first
5
- comparator_class = relation_hash.values.first
6
- define_method "check_#{type}".to_sym do |test, config|
7
- comparator_class
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]
8
28
  .new(config.is_a?(Hash) ? config : {expected: config})
9
- .compare(test[:source])
29
+ .compare(input[:source])
10
30
  .try { |error| fail error }
11
- end
12
31
  end
13
32
 
14
- compare :match => RegexpComparator
15
- compare :equal => EqualityComparator
16
- compare :contain => ContainComparator
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
38
+ end
17
39
  end
@@ -1,21 +1,22 @@
1
- class Comparator
2
- def initialize(opts)
3
- @expected = opts[:expected]
4
- @error_message = opts[:error]
5
- @config = opts
6
- setup if respond_to?(:setup, true)
1
+ class TextChecker::Comparator
2
+ def initialize(config = {})
3
+ @config = config
7
4
  end
8
5
 
9
6
  def compare(source)
10
- @error_message || error_message(source) unless success?(source)
7
+ @config[:error] || error_message(source) unless success?(transform(source))
8
+ end
9
+
10
+ def expected
11
+ transform @config[:expected]
11
12
  end
12
13
 
13
14
  private
14
15
 
15
16
  def modifiers
16
17
  modifiers = []
17
- modifiers << IgnoreWhitespace if @config[:ignore_whitespace]
18
- modifiers << IgnoreCase if @config[:ignore_case]
18
+ modifiers << TextChecker::IgnoreWhitespace if @config[:ignore_whitespace]
19
+ modifiers << TextChecker::IgnoreCase if @config[:ignore_case]
19
20
  modifiers
20
21
  end
21
22
 
@@ -1,11 +1,11 @@
1
- class ContainComparator < Comparator
2
-
3
- private
1
+ class TextChecker::ContainComparator < TextChecker::Comparator
4
2
 
5
3
  def success?(source)
6
- transform(source).include? transform(@expected)
4
+ source.include? expected.to_s
7
5
  end
8
6
 
7
+ private
8
+
9
9
  def error_message(source)
10
10
  I18n.t 'contain.failure', actual: source
11
11
  end
@@ -1,11 +1,11 @@
1
- class EqualityComparator < Comparator
2
-
3
- private
1
+ class TextChecker::EqualityComparator < TextChecker::Comparator
4
2
 
5
3
  def success?(source)
6
- transform(source) == transform(@expected)
4
+ source == expected.to_s
7
5
  end
8
6
 
7
+ private
8
+
9
9
  def error_message(source)
10
10
  I18n.t 'equality.failure', actual: source
11
11
  end
@@ -1,20 +1,13 @@
1
- class RegexpComparator < Comparator
2
-
3
- private
1
+ class TextChecker::RegexpComparator < TextChecker::Comparator
4
2
 
5
3
  def success?(source)
6
- !!@expected_regexp.match(source)
4
+ !!Regexp.new(expected).match(source)
7
5
  end
8
6
 
9
- def setup
10
- @expected_regexp = eval_regexp(@expected)
11
- end
7
+ private
8
+
12
9
 
13
10
  def error_message(source)
14
11
  I18n.t 'expression.failure', actual: source
15
12
  end
16
-
17
- def eval_regexp(expression)
18
- Regexp.new(expression)
19
- end
20
13
  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 CHANGED
@@ -5,3 +5,5 @@ en:
5
5
  failure: '**%{actual}** does not contain the right value.'
6
6
  expression:
7
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 CHANGED
@@ -4,4 +4,6 @@ es:
4
4
  contain:
5
5
  failure: '**%{actual}** no contiene el valor correcto.'
6
6
  expression:
7
- failure: '**%{actual}** no coincide con la expresión correcta.'
7
+ failure: '**%{actual}** no coincide con la expresión correcta.'
8
+ valid_ip:
9
+ failure: '**%{actual}** no es una dirección IP válida.'
@@ -1,7 +1,5 @@
1
- module IgnoreCase
2
- class << self
3
- def apply(text)
4
- text.downcase
5
- end
1
+ module TextChecker::IgnoreCase
2
+ def self.apply(text)
3
+ text.downcase
6
4
  end
7
5
  end
@@ -1,7 +1,5 @@
1
- module IgnoreWhitespace
2
- class << self
3
- def apply(text)
4
- text.delete(' ')
5
- end
1
+ module TextChecker::IgnoreWhitespace
2
+ def self.apply(text)
3
+ text.delete(' ')
6
4
  end
7
5
  end
data/lib/text_runner.rb CHANGED
@@ -12,12 +12,4 @@ require_relative './version_hook'
12
12
  require_relative './metadata_hook'
13
13
  require_relative './test_hook'
14
14
 
15
- require_relative './comparators/comparator'
16
- require_relative './comparators/equality_comparator'
17
- require_relative './comparators/contain_comparator'
18
- require_relative './comparators/regexp_comparator'
19
-
20
- require_relative './options/ignore_whitespace'
21
- require_relative './options/ignore_case'
22
-
23
15
  require_relative './checker'
data/lib/version_hook.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TextVersionHook
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-text-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.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: 2018-02-27 00:00:00.000000000 Z
11
+ date: 2018-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.7'
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.7'
26
+ version: '2.27'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +120,7 @@ files:
120
120
  - lib/comparators/contain_comparator.rb
121
121
  - lib/comparators/equality_comparator.rb
122
122
  - lib/comparators/regexp_comparator.rb
123
+ - lib/comparators/valid_ip_comparator.rb
123
124
  - lib/locales/en.yml
124
125
  - lib/locales/es.yml
125
126
  - lib/metadata_hook.rb
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  version: '0'
149
150
  requirements: []
150
151
  rubyforge_project:
151
- rubygems_version: 2.7.6
152
+ rubygems_version: 2.7.7
152
153
  signing_key:
153
154
  specification_version: 4
154
155
  summary: Text Runner for Mumuki