calificador 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +35 -16
- data/TODO.md +16 -0
- data/calificador.gemspec +54 -0
- data/lib/calificador.rb +8 -4
- data/lib/calificador/assert.rb +15 -0
- data/lib/calificador/assertor.rb +79 -35
- data/lib/calificador/build/attribute_evaluator.rb +34 -30
- data/lib/calificador/build/basic_factory.rb +195 -0
- data/lib/calificador/build/mock_factory.rb +151 -0
- data/lib/calificador/build/object_factory.rb +85 -0
- data/lib/calificador/build/trait.rb +0 -20
- data/lib/calificador/context/basic_context.rb +406 -0
- data/lib/calificador/context/class_method_context.rb +0 -0
- data/lib/calificador/{spec → context}/condition_context.rb +1 -3
- data/lib/calificador/{spec/type_context.rb → context/instance_context.rb} +5 -10
- data/lib/calificador/context/operation_context.rb +27 -0
- data/lib/calificador/context/override/argument_override.rb +73 -0
- data/lib/calificador/context/override/basic_override.rb +14 -0
- data/lib/calificador/context/override/factory_override.rb +31 -0
- data/lib/calificador/context/override/property_override.rb +61 -0
- data/lib/calificador/context/test_environment.rb +283 -0
- data/lib/calificador/{spec → context}/test_method.rb +2 -31
- data/lib/calificador/{spec → context}/test_root.rb +3 -15
- data/lib/calificador/{spec/examine_context.rb → context/type_context.rb} +7 -10
- data/lib/calificador/key.rb +27 -15
- data/lib/calificador/minitest/minitest_patches.rb +0 -2
- data/lib/calificador/test.rb +1 -3
- data/lib/calificador/test_mixin.rb +143 -139
- data/lib/calificador/util/call_formatter.rb +5 -5
- data/lib/calificador/util/core_extensions.rb +104 -79
- data/lib/calificador/util/proxy_object.rb +63 -0
- data/lib/calificador/version.rb +1 -1
- metadata +22 -42
- data/lib/calificador/build/attribute_container.rb +0 -103
- data/lib/calificador/build/factory.rb +0 -132
- data/lib/calificador/spec/basic_context.rb +0 -353
- data/lib/calificador/spec/class_method_context.rb +0 -42
- data/lib/calificador/spec/instance_method_context.rb +0 -38
- data/lib/calificador/spec/test_environment.rb +0 -141
- data/lib/calificador/spec/value_override.rb +0 -37
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
using Calificador::Util::CoreExtensions
|
4
|
-
|
5
|
-
module Calificador
|
6
|
-
module Spec
|
7
|
-
# Context that describes an instance method
|
8
|
-
class ClassMethodContext < BasicContext
|
9
|
-
class Dsl < BasicContext::Dsl
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :method
|
13
|
-
|
14
|
-
def initialize(parent:, method:, description: nil)
|
15
|
-
super(
|
16
|
-
parent: parent,
|
17
|
-
subject_key: parent.subject_key,
|
18
|
-
description: description,
|
19
|
-
overrides: {}
|
20
|
-
)
|
21
|
-
|
22
|
-
@method = method
|
23
|
-
end
|
24
|
-
|
25
|
-
def separate_description_by_space?
|
26
|
-
@parent && !@parent.is_a?(ExamineContext)
|
27
|
-
end
|
28
|
-
|
29
|
-
def create_subject(environment:, subject_key:)
|
30
|
-
subject_key.type
|
31
|
-
end
|
32
|
-
|
33
|
-
def create_result(subject:, arguments:, options:, block:)
|
34
|
-
if options.empty?
|
35
|
-
subject.send(@method, *arguments, &block)
|
36
|
-
else
|
37
|
-
subject.send(@method, *arguments, **options, &block)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
using Calificador::Util::CoreExtensions
|
4
|
-
|
5
|
-
module Calificador
|
6
|
-
module Spec
|
7
|
-
# Context that describes an instance method
|
8
|
-
class InstanceMethodContext < BasicContext
|
9
|
-
class Dsl < BasicContext::Dsl
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :method
|
13
|
-
|
14
|
-
def initialize(parent:, method:, description: nil)
|
15
|
-
super(
|
16
|
-
parent: parent,
|
17
|
-
subject_key: parent.subject_key,
|
18
|
-
description: description,
|
19
|
-
overrides: {}
|
20
|
-
)
|
21
|
-
|
22
|
-
@method = method
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_result(subject:, arguments:, options:, block:)
|
26
|
-
if options.empty?
|
27
|
-
subject.send(@method, *arguments, &block)
|
28
|
-
else
|
29
|
-
subject.send(@method, *arguments, **options, &block)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def separate_description_by_space?
|
34
|
-
@parent && !@parent.is_a?(ExamineContext)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
using Calificador::Util::CoreExtensions
|
4
|
-
|
5
|
-
module Calificador
|
6
|
-
module Spec
|
7
|
-
# Environment to run test method
|
8
|
-
class TestEnvironment
|
9
|
-
def initialize(test:, context:)
|
10
|
-
@test = test
|
11
|
-
@context = context
|
12
|
-
@subject = MISSING
|
13
|
-
@call_arguments = []
|
14
|
-
@call_options = {}
|
15
|
-
@call_block = nil
|
16
|
-
@call_result = MISSING
|
17
|
-
@created_objects = {}
|
18
|
-
@current_assertor = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def subject(value = MISSING)
|
22
|
-
if value.equal?(MISSING)
|
23
|
-
if @subject.equal?(MISSING)
|
24
|
-
@call_result = MISSING
|
25
|
-
@subject = @context.create_subject(environment: self, subject_key: @context.subject_key)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
@call_result = MISSING
|
29
|
-
@subject = value
|
30
|
-
end
|
31
|
-
|
32
|
-
@subject
|
33
|
-
end
|
34
|
-
|
35
|
-
def arguments(*arguments, **options, &block)
|
36
|
-
@call_arguments = arguments.nil? ? [] : arguments
|
37
|
-
@call_options = options.nil? ? {} : options
|
38
|
-
@call_block = block
|
39
|
-
@call_result = MISSING
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
|
43
|
-
def call(*arguments, **options, &block)
|
44
|
-
options.empty? ? arguments(*arguments, &block) : arguments(*arguments, **options, &block)
|
45
|
-
result
|
46
|
-
end
|
47
|
-
|
48
|
-
def result
|
49
|
-
if @call_result == MISSING
|
50
|
-
@call_result = @context.create_result(
|
51
|
-
subject: subject,
|
52
|
-
arguments: @call_arguments,
|
53
|
-
options: @call_options,
|
54
|
-
block: @call_block
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
@call_result
|
59
|
-
end
|
60
|
-
|
61
|
-
def create(type, trait = nil)
|
62
|
-
create_object(key: Key[type, trait])
|
63
|
-
end
|
64
|
-
|
65
|
-
def assert(&block)
|
66
|
-
@current_assertor&.__check_triggered
|
67
|
-
|
68
|
-
@current_assertor = Assertor.new(test: @test, block: block || __default_assert_block)
|
69
|
-
end
|
70
|
-
|
71
|
-
def refute(&block)
|
72
|
-
@current_assertor&.__check_triggered
|
73
|
-
|
74
|
-
@current_assertor = Assertor.new(test: @test, negated: true, block: block || __default_assert_block)
|
75
|
-
end
|
76
|
-
|
77
|
-
def respond_to_missing?(method, include_all)
|
78
|
-
@context.lookup_named_factory(name: method) || super
|
79
|
-
end
|
80
|
-
|
81
|
-
def method_missing(method, *arguments, **options, &block)
|
82
|
-
factory = @context.lookup_named_factory(name: method)
|
83
|
-
|
84
|
-
if factory
|
85
|
-
create_object(key: factory.key)
|
86
|
-
else
|
87
|
-
super
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def create_object(key:)
|
92
|
-
@created_objects.fetch(key) do
|
93
|
-
factory = @context.lookup_factory(key: key)
|
94
|
-
|
95
|
-
object = if factory.nil?
|
96
|
-
raise(KeyError, "No factory found for #{key}") if key.trait != Key::DEFAULT_TRAIT
|
97
|
-
|
98
|
-
constructor = key.type.method(:new)
|
99
|
-
constructor.invoke
|
100
|
-
else
|
101
|
-
factory.create(context: self)
|
102
|
-
end
|
103
|
-
|
104
|
-
@created_objects[key] = object
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def __done
|
109
|
-
@current_assertor&.__check_triggered
|
110
|
-
end
|
111
|
-
|
112
|
-
protected
|
113
|
-
|
114
|
-
def __default_assert_block
|
115
|
-
lambda do
|
116
|
-
result
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# def __pass(message = nil)
|
121
|
-
# @test.pass(message)
|
122
|
-
# end
|
123
|
-
|
124
|
-
# def __flunk(message = nil)
|
125
|
-
# @test.flunk(message)
|
126
|
-
# end
|
127
|
-
|
128
|
-
# def __assert(condition, message = nil)
|
129
|
-
# @test.assert(condition, message)
|
130
|
-
# end
|
131
|
-
|
132
|
-
# def __refute(condition, message = nil)
|
133
|
-
# @test.refute(condition, message)
|
134
|
-
# end
|
135
|
-
|
136
|
-
# def __exception_details(exception, message)
|
137
|
-
# @test.exception_details(exception, message)
|
138
|
-
# end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
using Calificador::Util::CoreExtensions
|
4
|
-
|
5
|
-
module Calificador
|
6
|
-
module Spec
|
7
|
-
# Factory calss
|
8
|
-
class ValueOverride
|
9
|
-
attr_reader :key, :values
|
10
|
-
|
11
|
-
def initialize(key:, values: {})
|
12
|
-
@key = key
|
13
|
-
@values = values.dup.freeze
|
14
|
-
end
|
15
|
-
|
16
|
-
def merge(other)
|
17
|
-
raise(ArgumentError, "Overrides must have same key") if @key != other.key
|
18
|
-
|
19
|
-
if other.values.empty? || equal?(other)
|
20
|
-
self
|
21
|
-
elsif @values.empty?
|
22
|
-
other
|
23
|
-
else
|
24
|
-
ValueOverride.new(key: @key, values: @values.merge(other.values))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def merge_values(values)
|
29
|
-
if values.empty?
|
30
|
-
self
|
31
|
-
else
|
32
|
-
ValueOverride.new(key: @key, values: @values.merge(values))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|