fix 1.0.0.beta4 → 1.0.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spectus/requirement/optional"
4
+ require "spectus/requirement/recommended"
5
+ require "spectus/requirement/required"
6
+
7
+ module Fix
8
+ # Collection of expectation matchers.
9
+ #
10
+ # @api private
11
+ module Requirement
12
+ # rubocop:disable Naming/MethodName
13
+
14
+ # This method mean that the definition is an absolute requirement of the
15
+ # specification.
16
+ #
17
+ # @param matcher [#matches?] The matcher.
18
+ #
19
+ # @return [Requirement::Required] An absolute requirement level instance.
20
+ #
21
+ # @api public
22
+ def MUST(matcher)
23
+ ::Spectus::Requirement::Required.new(
24
+ isolate: false,
25
+ negate: false,
26
+ matcher: matcher
27
+ )
28
+ end
29
+
30
+ # @see MUST
31
+ #
32
+ # @api public
33
+ def MUST!(matcher)
34
+ ::Spectus::Requirement::Required.new(
35
+ isolate: true,
36
+ negate: false,
37
+ matcher: matcher
38
+ )
39
+ end
40
+
41
+ # This method mean that the definition is an absolute prohibition of the specification.
42
+ #
43
+ # @param matcher [#matches?] The matcher.
44
+ #
45
+ # @return [Requirement::Required] An absolute prohibition level instance.
46
+ #
47
+ # @api public
48
+ def MUST_NOT(matcher)
49
+ ::Spectus::Requirement::Required.new(
50
+ isolate: false,
51
+ negate: true,
52
+ matcher: matcher
53
+ )
54
+ end
55
+
56
+ # @see MUST_NOT
57
+ #
58
+ # @api public
59
+ def MUST_NOT!(matcher)
60
+ ::Spectus::Requirement::Required.new(
61
+ isolate: true,
62
+ negate: true,
63
+ matcher: matcher
64
+ )
65
+ end
66
+
67
+ # This method mean that there may exist valid reasons in particular
68
+ # circumstances to ignore a particular item, but the full implications must be
69
+ # understood and carefully weighed before choosing a different course.
70
+ #
71
+ # @param matcher [#matches?] The matcher.
72
+ #
73
+ # @return [Requirement::Recommended] A recommended requirement level instance.
74
+ #
75
+ # @api public
76
+ def SHOULD(matcher)
77
+ ::Spectus::Requirement::Recommended.new(
78
+ isolate: false,
79
+ negate: false,
80
+ matcher: matcher
81
+ )
82
+ end
83
+
84
+ # @see SHOULD
85
+ #
86
+ # @api public
87
+ def SHOULD!(matcher)
88
+ ::Spectus::Requirement::Recommended.new(
89
+ isolate: true,
90
+ negate: false,
91
+ matcher: matcher
92
+ )
93
+ end
94
+
95
+ # This method mean that there may exist valid reasons in particular
96
+ # circumstances when the particular behavior is acceptable or even useful, but
97
+ # the full implications should be understood and the case carefully weighed
98
+ # before implementing any behavior described with this label.
99
+ #
100
+ # @param matcher [#matches?] The matcher.
101
+ #
102
+ # @return [Requirement::Recommended] A not recommended requirement level
103
+ # instance.
104
+ #
105
+ # @api public
106
+ def SHOULD_NOT(matcher)
107
+ ::Spectus::Requirement::Recommended.new(
108
+ isolate: false,
109
+ negate: true,
110
+ matcher: matcher
111
+ )
112
+ end
113
+
114
+ # @see SHOULD_NOT
115
+ #
116
+ # @api public
117
+ def SHOULD_NOT!(matcher)
118
+ ::Spectus::Requirement::Recommended.new(
119
+ isolate: true,
120
+ negate: true,
121
+ matcher: matcher
122
+ )
123
+ end
124
+
125
+ # This method mean that an item is truly optional.
126
+ # One vendor may choose to include the item because a particular marketplace
127
+ # requires it or because the vendor feels that it enhances the product while
128
+ # another vendor may omit the same item. An implementation which does not
129
+ # include a particular option must be prepared to interoperate with another
130
+ # implementation which does include the option, though perhaps with reduced
131
+ # functionality. In the same vein an implementation which does include a
132
+ # particular option must be prepared to interoperate with another
133
+ # implementation which does not include the option (except, of course, for the
134
+ # feature the option provides).
135
+ #
136
+ # @param matcher [#matches?] The matcher.
137
+ #
138
+ # @return [Requirement::Optional] An optional requirement level instance.
139
+ #
140
+ # @api public
141
+ def MAY(matcher)
142
+ ::Spectus::Requirement::Optional.new(
143
+ isolate: false,
144
+ negate: false,
145
+ matcher: matcher
146
+ )
147
+ end
148
+
149
+ # @see MAY
150
+ #
151
+ # @api public
152
+ def MAY!(matcher)
153
+ ::Spectus::Requirement::Optional.new(
154
+ isolate: true,
155
+ negate: false,
156
+ matcher: matcher
157
+ )
158
+ end
159
+
160
+ # rubocop:enable Naming/MethodName
161
+ end
162
+ end
data/lib/fix/run.rb ADDED
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "expresenter/fail"
4
+
5
+ module Fix
6
+ # Run class.
7
+ #
8
+ # @api private
9
+ class Run
10
+ # @return [::Fix::Dsl] A context instance.
11
+ attr_reader :environment
12
+
13
+ # @return [::Spectus::Requirement::Base] An expectation.
14
+ attr_reader :requirement
15
+
16
+ # @return [Array<::Defi::Challenge>] A list of challenges.
17
+ attr_reader :challenges
18
+
19
+ # @param environment [::Fix::Dsl] A context instance.
20
+ # @param requirement [::Spectus::Requirement::Base] An expectation.
21
+ # @param challenges [Array<::Defi::Challenge>] A list of challenges.
22
+ def initialize(environment, requirement, *challenges)
23
+ @environment = environment
24
+ @requirement = requirement
25
+ @challenges = challenges
26
+ end
27
+
28
+ # Verify if the object checks the condition.
29
+ #
30
+ # @param subject [Proc] The block of code to be tested.
31
+ #
32
+ # @raise [::Expresenter::Fail] A failed spec exception.
33
+ # @return [::Expresenter::Pass] A passed spec instance.
34
+ #
35
+ # @see https://github.com/fixrb/expresenter
36
+ def against(&subject)
37
+ requirement.call { actual_value(&subject) }
38
+ rescue ::Expresenter::Fail => e
39
+ e
40
+ end
41
+
42
+ private
43
+
44
+ # The test's actual value.
45
+ #
46
+ # @param subject [Proc] The block of code to be tested.
47
+ #
48
+ # @return [#object_id] The actual value to be tested.
49
+ def actual_value(&subject)
50
+ challenges.inject(environment.instance_eval(&subject)) do |obj, challenge|
51
+ challenge.to(obj).call
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/fix/set.rb ADDED
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "doc"
4
+ require_relative "run"
5
+
6
+ module Fix
7
+ # Collection of specifications.
8
+ #
9
+ # @api private
10
+ class Set
11
+ # The type of result.
12
+ #
13
+ # Passed expectations can be classified as:
14
+ #
15
+ # * `success`
16
+ # * `warning`
17
+ # * `info`
18
+ #
19
+ # Failed expectations can be classified as:
20
+ #
21
+ # * `failure`
22
+ # * `error`
23
+ LOG_LEVELS = %w[
24
+ none
25
+ error
26
+ failure
27
+ warning
28
+ info
29
+ success
30
+ ].freeze
31
+
32
+ # @return [Array] A list of specifications.
33
+ attr_reader :specs
34
+
35
+ # @param name [String, Symbol] The constant name of the specifications.
36
+ #
37
+ # @api public
38
+ def self.load(name)
39
+ new(*Doc.fetch(name))
40
+ end
41
+
42
+ # @param contexts [Array<::Fix::Dsl>] The list of contexts document.
43
+ def initialize(*contexts)
44
+ @specs = Doc.specs(*contexts)
45
+ @passed = true
46
+ end
47
+
48
+ # @param subject [Proc] The block of code to be tested.
49
+ #
50
+ # @raise [::SystemExit] The test set failed!
51
+ #
52
+ # @api public
53
+ def against(log_level: 5, &subject)
54
+ randomize!
55
+
56
+ specs.each do |environment, location, requirement, challenges|
57
+ runner = Run.new(environment, requirement, *challenges)
58
+ result = runner.against(&subject)
59
+
60
+ failed! if result.failed?
61
+ report!(location, result, log_level: log_level)
62
+ end
63
+
64
+ passed? || ::Kernel.exit(false)
65
+ end
66
+
67
+ private
68
+
69
+ def randomize!
70
+ specs.shuffle!
71
+ end
72
+
73
+ def failed!
74
+ @passed = false
75
+ end
76
+
77
+ # @return [Boolean] The test set passed or failed.
78
+ def passed?
79
+ @passed
80
+ end
81
+
82
+ def report!(path, result, log_level:)
83
+ return unless report?(result, log_level: log_level)
84
+
85
+ puts "#{path} #{result.colored_string}"
86
+ end
87
+
88
+ def report?(result, log_level:)
89
+ LOG_LEVELS[1..log_level].any? { |name| result.public_send("#{name}?") }
90
+ end
91
+ end
92
+ end
data/lib/kernel.rb CHANGED
@@ -1,9 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative File.join("fix", "doc")
4
+ require_relative File.join("fix", "dsl")
5
+ require_relative File.join("fix", "set")
6
+
7
+ # The Kernel module.
3
8
  module Kernel
4
9
  # rubocop:disable Naming/MethodName
5
- def Fix(subject = nil, **lets, &block)
6
- ::Fix.describe(subject, **lets, &block)
10
+
11
+ # Specifications are built with this method.
12
+ #
13
+ # @example Require an answer equal to 42.
14
+ # # The spec
15
+ # Fix :Answer do
16
+ # it MUST equal 42
17
+ # end
18
+ #
19
+ # # A test
20
+ # Fix[:Answer].against { 42 }
21
+ #
22
+ # @param name [String, Symbol] The constant name of the specifications.
23
+ # @param block [Proc] The specifications.
24
+ #
25
+ # @return [#against] The collection of specifications.
26
+ #
27
+ # @api public
28
+ def Fix(name = nil, &block)
29
+ klass = ::Class.new(::Fix::Dsl)
30
+ klass.const_set(:CONTEXTS, [klass])
31
+ klass.instance_eval(&block)
32
+ ::Fix::Doc.const_set(name, klass) unless name.nil?
33
+ ::Fix::Set.new(*klass.const_get(:CONTEXTS))
7
34
  end
8
35
  # rubocop:enable Naming/MethodName
9
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: defi
@@ -16,70 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.4
19
+ version: 2.0.5
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.0.4
26
+ version: 2.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: matchi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.3.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: spectus
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 3.1.2
47
+ version: 4.0.2
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 3.1.2
54
+ version: 4.0.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '2.1'
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '2.1'
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: '13.0'
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: '13.0'
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rubocop
84
+ name: rubocop-md
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '0.79'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '0.79'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop-performance
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,35 +108,63 @@ dependencies:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-thread_safety
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: simplecov
99
141
  requirement: !ruby/object:Gem::Requirement
100
142
  requirements:
101
- - - "~>"
143
+ - - ">="
102
144
  - !ruby/object:Gem::Version
103
- version: '0.17'
145
+ version: '0'
104
146
  type: :development
105
147
  prerelease: false
106
148
  version_requirements: !ruby/object:Gem::Requirement
107
149
  requirements:
108
- - - "~>"
150
+ - - ">="
109
151
  - !ruby/object:Gem::Version
110
- version: '0.17'
152
+ version: '0'
111
153
  - !ruby/object:Gem::Dependency
112
154
  name: yard
113
155
  requirement: !ruby/object:Gem::Requirement
114
156
  requirements:
115
- - - "~>"
157
+ - - ">="
116
158
  - !ruby/object:Gem::Version
117
- version: '0.9'
159
+ version: '0'
118
160
  type: :development
119
161
  prerelease: false
120
162
  version_requirements: !ruby/object:Gem::Requirement
121
163
  requirements:
122
- - - "~>"
164
+ - - ">="
123
165
  - !ruby/object:Gem::Version
124
- version: '0.9'
125
- description: Specing framework for Ruby.
166
+ version: '0'
167
+ description: Specing framework.
126
168
  email: contact@cyril.email
127
169
  executables: []
128
170
  extensions: []
@@ -131,16 +173,21 @@ files:
131
173
  - LICENSE.md
132
174
  - README.md
133
175
  - lib/fix.rb
134
- - lib/fix/context.rb
135
- - lib/fix/expectation_result_not_found_error.rb
136
- - lib/fix/it.rb
137
- - lib/fix/suspicious_success_error.rb
176
+ - lib/fix/doc.rb
177
+ - lib/fix/dsl.rb
178
+ - lib/fix/matcher.rb
179
+ - lib/fix/requirement.rb
180
+ - lib/fix/run.rb
181
+ - lib/fix/set.rb
138
182
  - lib/kernel.rb
139
183
  homepage: https://fixrb.dev/
140
184
  licenses:
141
185
  - MIT
142
186
  metadata:
187
+ bug_tracker_uri: https://github.com/fixrb/fix/issues
188
+ documentation_uri: https://rubydoc.info/gems/fix
143
189
  source_code_uri: https://github.com/fixrb/fix
190
+ wiki_uri: https://github.com/fixrb/fix/wiki
144
191
  post_install_message:
145
192
  rdoc_options: []
146
193
  require_paths:
@@ -149,15 +196,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
196
  requirements:
150
197
  - - ">="
151
198
  - !ruby/object:Gem::Version
152
- version: 2.3.0
199
+ version: 2.7.0
153
200
  required_rubygems_version: !ruby/object:Gem::Requirement
154
201
  requirements:
155
202
  - - ">"
156
203
  - !ruby/object:Gem::Version
157
204
  version: 1.3.1
158
205
  requirements: []
159
- rubygems_version: 3.1.2
206
+ rubygems_version: 3.1.6
160
207
  signing_key:
161
208
  specification_version: 4
162
- summary: Specing framework for Ruby.
209
+ summary: Specing framework.
163
210
  test_files: []