evt-mimic 2.3.1.3 → 2.4.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e914127f63af9cf5a3f1eaf9bbe106e95cc390241cf1bfb34e5f7f30312e91f
4
- data.tar.gz: 59f35d69cddfb389232537da6857be6c4d2a980172c9dd8021384017e503de10
3
+ metadata.gz: 9468c4c7587043c95360409630059292adf92918f020b2d00f6a2e9624603b2b
4
+ data.tar.gz: 2cade7760be20b62576bc14b6fc9196e0746bfde1b405b952323c6f76843640b
5
5
  SHA512:
6
- metadata.gz: 558016928680a0aa153522429c38e7f25f662a8f2cdcdb41f9820b8d7e7a4181378d8a3ac91438f7e2f8bb44ccbeea49664fe41f42445717a1b21e5bc049cea4
7
- data.tar.gz: 553605c025140b601baa51e0b9b75304a0e8f2905e828c5efd724220af21ef7b7a258889e64bf818a0cc5833a992b895edc6097ea34c5fc2dc7d6d62bcc07372
6
+ metadata.gz: 50ba21cea181413df366aae9694235ee9a1359dd27ff901620fa5a048016d9c6003790effc91e85e1171ac0b8eadf15458509d6508cd39066bf1a387d375c296
7
+ data.tar.gz: c212957a42c6d397fdfaf20bd58b0c9f362c42a5732a7f1ca367946cd228dfc366a7fe4b6cc0d3f52ef1955eb215a9e3358af04aafb0c593e1864ad2f6dcbe59
data/lib/mimic/build.rb CHANGED
@@ -3,7 +3,7 @@ module Mimic
3
3
  def self.call(subject_class, record: nil, &blk)
4
4
  record ||= false
5
5
 
6
- cls = Class.build(subject_class, &blk)
6
+ cls = Class.build(subject_class)
7
7
 
8
8
  subject_methods = Mimic.subject_methods(cls)
9
9
 
@@ -19,6 +19,10 @@ module Mimic
19
19
 
20
20
  DefineMethods.(cls, subject_methods, record: record)
21
21
 
22
+ if not blk.nil?
23
+ cls.class_exec(&blk)
24
+ end
25
+
22
26
  cls
23
27
  end
24
28
  end
@@ -2,8 +2,6 @@ module Mimic
2
2
  module Controls
3
3
  module Invocation
4
4
  def self.example
5
- method_name = :some_method
6
-
7
5
  parameters = {}
8
6
  parameters[:some_parameter] = 1
9
7
  parameters[:some_other_parameter] = 11
@@ -12,6 +10,24 @@ module Mimic
12
10
 
13
11
  invocation
14
12
  end
13
+
14
+ def self.other_example
15
+ parameters = {}
16
+ parameters[:some_parameter] = 111
17
+ parameters[:some_other_parameter] = 1111
18
+
19
+ invocation = ::Invocation.new(other_method_name, parameters)
20
+
21
+ invocation
22
+ end
23
+
24
+ def self.method_name
25
+ :some_method
26
+ end
27
+
28
+ def self.other_method_name
29
+ :some_other_method
30
+ end
15
31
  end
16
32
  end
17
33
  end
@@ -2,7 +2,21 @@ module Mimic
2
2
  module Controls
3
3
  module Mimic
4
4
  def self.example
5
- ::Mimic.(Subject::Class.example)
5
+ ::Mimic.(subject_class)
6
+ end
7
+
8
+ def self.subject_class
9
+ Subject::PositionalParameters::Example
10
+ end
11
+
12
+ module Predicate
13
+ def self.example(strict: nil)
14
+ ::Mimic.(Mimic.subject_class, record: true) do
15
+ include ::Mimic::Recorder::Predicate
16
+
17
+ predicate :some_predicate?, method_name: :some_method, strict: strict
18
+ end
19
+ end
6
20
  end
7
21
  end
8
22
  end
@@ -0,0 +1,24 @@
1
+ module Mimic
2
+ module Recorder
3
+ module Predicate
4
+ def self.included(cls)
5
+ cls.class_exec do
6
+ extend Macro
7
+ end
8
+ end
9
+
10
+ module Macro
11
+ def predicate(predicate_name, method_name:, strict: nil)
12
+ if strict.nil?
13
+ strict = true
14
+ end
15
+
16
+ send(:define_method, predicate_name) do |**parameters|
17
+ parameters[:strict] = strict
18
+ invoked?(method_name, **parameters)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,7 @@
1
1
  module Mimic
2
2
  module Recorder
3
+ Error = ::Class.new(RuntimeError)
4
+
3
5
  attr_writer :__records
4
6
  def __records
5
7
  @__records ||= []
@@ -12,25 +14,38 @@ module Mimic
12
14
  end
13
15
  alias :record :__record
14
16
 
15
- def __invocation(method_name, &blk)
16
- invocations = __invocations(method_name, &blk)
17
+ def __invocation(method_name, **parameters)
18
+ strict = parameters.delete(:strict)
19
+ strict ||= false
20
+
21
+ invocations = __invocations(method_name, **parameters)
17
22
 
18
23
  if invocations.empty?
19
24
  return nil
20
25
  end
21
26
 
22
- return invocations.first
27
+ if strict && invocations.length > 1
28
+ raise Error, "More than one invocation record matches (Method Name: #{method_name.inspect}, Parameters: #{parameters.inspect})"
29
+ end
30
+
31
+ invocations.first
23
32
  end
24
33
  alias :invocation :__invocation
25
34
 
26
- def __invocations(method_name=nil, &blk)
27
- if method_name.nil? && blk.nil?
35
+ def __one_invocation(method_name, **parameters)
36
+ parameters[:strict] = true
37
+ __invocation(method_name, **parameters)
38
+ end
39
+ alias :one_invocation :__one_invocation
40
+
41
+ def __invocations(method_name=nil, **parameters)
42
+ if method_name.nil? && parameters.empty?
28
43
  return __records
29
44
  end
30
45
 
31
46
  invocations = __records.select { |invocation| invocation.method_name == method_name }
32
47
 
33
- if blk.nil?
48
+ if parameters.nil?
34
49
  return invocations
35
50
  end
36
51
 
@@ -38,16 +53,36 @@ module Mimic
38
53
  return []
39
54
  end
40
55
 
41
- invocations.select do |invocation|
42
- invocation.parameters.find { |k, v| blk.(k, v)}
56
+ invocations = invocations.select do |invocation|
57
+ parameters.all? do |match_parameter_name, match_parameter_value|
58
+ invocation_value = invocation.parameters[match_parameter_name]
59
+
60
+ invocation_value == match_parameter_value
61
+ end
43
62
  end
63
+
64
+ invocations
44
65
  end
45
66
  alias :invocations :__invocations
46
67
 
47
- def __invoked?(method_name, &blk)
48
- invocation = __invocation(method_name, &blk)
68
+ def __invoked?(method_name=nil, **parameters)
69
+ if method_name.nil? && parameters.empty?
70
+ return !__records.empty?
71
+ end
72
+
73
+ if not parameters.key?(:strict)
74
+ parameters[:strict] = false
75
+ end
76
+
77
+ invocation = __invocation(method_name, **parameters)
49
78
  !invocation.nil?
50
79
  end
51
80
  alias :invoked? :__invoked?
81
+
82
+ def __invoked_once?(method_name, **parameters)
83
+ parameters[:strict] = true
84
+ __invoked?(method_name, **parameters)
85
+ end
86
+ alias :invoked_once? :__invoked_once?
52
87
  end
53
88
  end
data/lib/mimic.rb CHANGED
@@ -10,4 +10,5 @@ require 'mimic/void'
10
10
  require 'mimic/remove_methods'
11
11
  require 'mimic/define_methods'
12
12
  require 'mimic/recorder'
13
+ require 'mimic/recorder/predicate'
13
14
  require 'mimic/mimic'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-mimic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1.3
4
+ version: 2.4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-25 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-invocation
@@ -68,6 +68,7 @@ files:
68
68
  - lib/mimic/predicates/method/parameters.rb
69
69
  - lib/mimic/preserved_methods.rb
70
70
  - lib/mimic/recorder.rb
71
+ - lib/mimic/recorder/predicate.rb
71
72
  - lib/mimic/remove_methods.rb
72
73
  - lib/mimic/subject_methods.rb
73
74
  - lib/mimic/void.rb
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  requirements: []
93
- rubygems_version: 3.3.3
94
+ rubygems_version: 3.4.6
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Copy a class's instance interface to an anonymous, new object that acts as