mumuki-text-runner 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGJhYTFkYjAyOGRiZDZmMWQxMjcyZGIwNjU5OTVlNjRkZmMwZDlkZA==
5
- data.tar.gz: !binary |-
6
- N2JkZmE5ZDRhYzY1YzM5MDZjNGJkMmRhNzM3MDM0ZjIxZTYwNjlkMA==
2
+ SHA256:
3
+ metadata.gz: ff637b59a63ae832dbb1707f9ca1c5fd43a1df4a70531d307626449007e59e1c
4
+ data.tar.gz: a936a8b9382eb3219615f006fd41b7c2c551b33a5f220bdf087faf6fb8b94770
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YzIwYTQ3OTYyY2Q0MzVhZmY4OTliNzE0YmI0ZWVlN2RlZTdmOTBkNzJjYjMx
10
- YzIxMDkxZWI1MWU4MjVjNzcyZWIxMDcwYmQzMjk3ZmQ2ODdkYzI5NWU4MWU5
11
- N2VhYmUxYzJiM2U2OTgxYzEzMGQ2ZmQ0MjlhZDg5NzRlODk0MGM=
12
- data.tar.gz: !binary |-
13
- YzVmZDZiMGNiOTAxZjY4NWVjMGRkNGNlYzQ0NzM2YTRlYmVkYTE1YTVjNGNm
14
- YjBiN2Q1MWJlNjNjNWU1ZmM5NDcwODc5NDcxZTRhNDgzODBjYmFkM2UxYTVh
15
- YTEzZWM1NDdlMDdhNDNjNTNhZDRlOWI1ZDJiOGU0YTJiNDRhYjQ=
6
+ metadata.gz: 4ac21ef25b3fb829eb341bde542388285436dccb5f24f99a541579ccf78528ced3d45b2c037124df368fe51d1bdaa018885ea38b32d05871860dda3f3fa35259
7
+ data.tar.gz: edb1488843f13aa4046ed7d695425067a1069d965119e80cea903da2ca6c0c64e88ba75263af341e656fd975cacf8fac346fb8f5f801b4faed1cc1f7aaedce63
data/lib/checker.rb CHANGED
@@ -1,7 +1,17 @@
1
1
  class TextChecker < Mumukit::Metatest::Checker
2
- def check_equal(test, config)
3
- actual = test[:source]
4
- comparer = EqualityComparer.new(config)
5
- fail comparer.locale_error_message unless comparer.satisfies?(actual)
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
8
+ .new(config.is_a?(Hash) ? config : {expected: config})
9
+ .compare(test[:source])
10
+ .try { |error| fail error }
11
+ end
6
12
  end
13
+
14
+ compare :match => RegexpComparator
15
+ compare :equal => EqualityComparator
16
+ compare :contain => ContainComparator
7
17
  end
@@ -0,0 +1,25 @@
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)
7
+ end
8
+
9
+ def compare(source)
10
+ @error_message || error_message(source) unless success?(source)
11
+ end
12
+
13
+ private
14
+
15
+ def modifiers
16
+ modifiers = []
17
+ modifiers << IgnoreWhitespace if @config[:ignore_whitespace]
18
+ modifiers << IgnoreCase if @config[:ignore_case]
19
+ modifiers
20
+ end
21
+
22
+ def transform(source)
23
+ modifiers.inject(source) { |text, modifier| modifier.apply(text) }
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ class ContainComparator < Comparator
2
+
3
+ private
4
+
5
+ def success?(source)
6
+ transform(source).include? transform(@expected)
7
+ end
8
+
9
+ def error_message(source)
10
+ I18n.t 'contain.failure', actual: source
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class EqualityComparator < Comparator
2
+
3
+ private
4
+
5
+ def success?(source)
6
+ transform(source) == transform(@expected)
7
+ end
8
+
9
+ def error_message(source)
10
+ I18n.t 'equality.failure', actual: source
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ class RegexpComparator < Comparator
2
+
3
+ private
4
+
5
+ def success?(source)
6
+ !!@expected_regexp.match(source)
7
+ end
8
+
9
+ def setup
10
+ @expected_regexp = eval_regexp(@expected)
11
+ end
12
+
13
+ def error_message(source)
14
+ I18n.t 'expression.failure', actual: source
15
+ end
16
+
17
+ def eval_regexp(expression)
18
+ Regexp.new(expression)
19
+ end
20
+ end
data/lib/locales/en.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  en:
2
2
  equality:
3
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.'
data/lib/locales/es.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  es:
2
2
  equality:
3
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.'
data/lib/metadata_hook.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  class TextMetadataHook < Mumukit::Hook
2
2
  def metadata
3
3
  { language: {
4
- name: 'text',
5
- icon: { type: 'devicon', name: 'code' },
6
- extension: 'txt',
7
- test_framework: {
8
4
  name: 'text',
9
- test_extension: 'yml'
10
- }
5
+ icon: { type: 'devicon', name: 'code' },
6
+ extension: 'txt',
7
+ test_framework: {
8
+ name: 'text',
9
+ test_extension: 'yml'
10
+ }
11
11
  } }
12
12
  end
13
13
  end
data/lib/test_hook.rb CHANGED
@@ -2,7 +2,7 @@ require 'mumukit/hook'
2
2
 
3
3
  class TextTestHook < Mumukit::Hook
4
4
  def compile(request)
5
- {source: request[:content].strip, examples: parse_test(request[:test])}
5
+ { source: request[:content].strip, examples: parse_test(request[:test]) }
6
6
  end
7
7
 
8
8
  def run!(test_definition)
@@ -23,15 +23,14 @@ class TextTestHook < Mumukit::Hook
23
23
  else
24
24
  parse_single_scenario_test(parsed_test)
25
25
  end
26
-
27
26
  end
28
27
 
29
28
  def parse_single_scenario_test(parsed_test)
30
- [{name: 'test',
31
- postconditions: {equal: {
32
- expected: parsed_test['equal'],
33
- ignore_case: parsed_test['ignore_case'].present?,
34
- ignore_whitespace: parsed_test['ignore_whitespace'].present?}}
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? } }
35
34
  }]
36
35
  end
37
36
 
data/lib/text_runner.rb CHANGED
@@ -8,11 +8,16 @@ Mumukit.configure do |config|
8
8
  config.content_type = 'markdown'
9
9
  end
10
10
 
11
+ require_relative './version_hook'
11
12
  require_relative './metadata_hook'
12
13
  require_relative './test_hook'
13
14
 
14
- require_relative './checker'
15
+ require_relative './comparators/comparator'
16
+ require_relative './comparators/equality_comparator'
17
+ require_relative './comparators/contain_comparator'
18
+ require_relative './comparators/regexp_comparator'
15
19
 
16
- require_relative './comparers/equality_comparer'
17
20
  require_relative './options/ignore_whitespace'
18
21
  require_relative './options/ignore_case'
22
+
23
+ require_relative './checker'
@@ -0,0 +1,3 @@
1
+ module TextVersionHook
2
+ VERSION = '1.2.1'
3
+ end
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.1.0
4
+ version: 1.2.1
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: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2018-02-27 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.6'
19
+ version: '2.7'
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.6'
26
+ version: '2.7'
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
33
  version: '1.7'
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
40
  version: '1.7'
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.3'
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.3'
110
+ version: '3.1'
97
111
  description:
98
112
  email:
99
113
  - franco@mumuki.org
@@ -102,7 +116,10 @@ extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
118
  - lib/checker.rb
105
- - lib/comparers/equality_comparer.rb
119
+ - lib/comparators/comparator.rb
120
+ - lib/comparators/contain_comparator.rb
121
+ - lib/comparators/equality_comparator.rb
122
+ - lib/comparators/regexp_comparator.rb
106
123
  - lib/locales/en.yml
107
124
  - lib/locales/es.yml
108
125
  - lib/metadata_hook.rb
@@ -110,6 +127,7 @@ files:
110
127
  - lib/options/ignore_whitespace.rb
111
128
  - lib/test_hook.rb
112
129
  - lib/text_runner.rb
130
+ - lib/version_hook.rb
113
131
  homepage: http://github.com/mumuki/mumuki-text-server
114
132
  licenses:
115
133
  - MIT
@@ -120,17 +138,17 @@ require_paths:
120
138
  - lib
121
139
  required_ruby_version: !ruby/object:Gem::Requirement
122
140
  requirements:
123
- - - ! '>='
141
+ - - ">="
124
142
  - !ruby/object:Gem::Version
125
143
  version: '0'
126
144
  required_rubygems_version: !ruby/object:Gem::Requirement
127
145
  requirements:
128
- - - ! '>='
146
+ - - ">="
129
147
  - !ruby/object:Gem::Version
130
148
  version: '0'
131
149
  requirements: []
132
150
  rubyforge_project:
133
- rubygems_version: 2.4.5
151
+ rubygems_version: 2.7.6
134
152
  signing_key:
135
153
  specification_version: 4
136
154
  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 == transform(@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