evt-mimic 2.3.1.4 → 2.4.0.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: 0add0e7fe81fc75241500f37747288fb82a6500cabb367a41a35b90122e773ea
4
- data.tar.gz: 8c5c2b216a959dad72f0fb8735b196de4d6d1f4d7fe4143d363e2aa875486ad7
3
+ metadata.gz: 9468c4c7587043c95360409630059292adf92918f020b2d00f6a2e9624603b2b
4
+ data.tar.gz: 2cade7760be20b62576bc14b6fc9196e0746bfde1b405b952323c6f76843640b
5
5
  SHA512:
6
- metadata.gz: 8c41ee2a70a26f902c7706c3e6739f0aa13562e850f6aef3e3b62a260a0a719aec4c0f95eae2055734ff7109f617d31483c252aaf18e788bc62bf363a554b754
7
- data.tar.gz: d825ea96f99d897b99d3c26051e5fedac35e977308ac4a3688a404cf5bd13d483acd8de8ab9e056c0fbdb4171edaf28ea890645d691805a7b3da4b0f5a42b40b
6
+ metadata.gz: 50ba21cea181413df366aae9694235ee9a1359dd27ff901620fa5a048016d9c6003790effc91e85e1171ac0b8eadf15458509d6508cd39066bf1a387d375c296
7
+ data.tar.gz: c212957a42c6d397fdfaf20bd58b0c9f362c42a5732a7f1ca367946cd228dfc366a7fe4b6cc0d3f52ef1955eb215a9e3358af04aafb0c593e1864ad2f6dcbe59
@@ -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.4
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-11-01 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