simple-service 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yaml +25 -0
- data/Gemfile +2 -2
- data/VERSION +1 -1
- data/lib/simple/service/action/method_reflection.rb +3 -2
- data/lib/simple/service/action.rb +20 -6
- data/lib/simple/service/errors.rb +19 -5
- data/lib/simple/service.rb +9 -1
- data/simple-service.gemspec +1 -1
- data/spec/simple/service/action_invoke3_spec.rb +64 -61
- data/spec/simple/service/action_invoke_spec.rb +39 -46
- data/spec/simple/service/service_spec.rb +10 -25
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 930f3a5be0e5f968df791450b544e023bda72c76212032e8879bcdbdbd30dbde
|
4
|
+
data.tar.gz: 6827c9d687f3bcd9a5a9cb5a5d0a7625423c5e6124f5a402aad76a6bdf0aee0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9cd282beef0ce7f596aee2f7283d9307f2f6269a2c235315dceddce9909eff543459aeb3f2babce6bfe2f9239b880f9abca0bc4a146b8fc0b9e38ee034ef78
|
7
|
+
data.tar.gz: 201a2a182ad2264570f401fd5356f14d1c9543562c1e665cde4bfb99d264afa4b65e23b1fbaf0606b73f2c49b73f175b99fe9fd5e2fbc175441718c75b16f2f1
|
@@ -0,0 +1,25 @@
|
|
1
|
+
on: push
|
2
|
+
jobs:
|
3
|
+
test:
|
4
|
+
runs-on: ubuntu-latest
|
5
|
+
|
6
|
+
# https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
ruby_version: [2.7, 3.1.2]
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
# Not needed with a .ruby-version file
|
19
|
+
ruby-version: ${{ matrix.ruby_version }}
|
20
|
+
# runs 'bundle install' and caches installed gems automatically
|
21
|
+
bundler-cache: true
|
22
|
+
|
23
|
+
- name: Run tests
|
24
|
+
run: |
|
25
|
+
bundle exec rspec
|
data/Gemfile
CHANGED
@@ -6,8 +6,8 @@ gemspec
|
|
6
6
|
# --- Development and test dependencies ------------------------------
|
7
7
|
|
8
8
|
group :development, :test do
|
9
|
-
gem 'rake'
|
10
|
-
gem 'rspec'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rspec'
|
11
11
|
# gem 'rubocop', '~> 0.61.1'
|
12
12
|
gem 'simplecov', '~> 0'
|
13
13
|
gem 'pry-byebug'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# rubocop:disable Metrics/AbcSize
|
1
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
2
2
|
|
3
3
|
module ::Simple::Service::Action::MethodReflection # @private
|
4
4
|
extend self
|
@@ -29,13 +29,14 @@ module ::Simple::Service::Action::MethodReflection # @private
|
|
29
29
|
|
30
30
|
fake_recipient = Object.new.extend(service)
|
31
31
|
fake_call_args = minimal_arguments(method)
|
32
|
+
fake_call_kwargs = fake_call_args.last.is_a?(Hash) ? fake_call_args.pop : {}
|
32
33
|
|
33
34
|
trace_point = TracePoint.trace(:call) do |tp|
|
34
35
|
throw :received_fake_call, tp.binding if tp.defined_class == service && tp.method_id == method_id
|
35
36
|
end
|
36
37
|
|
37
38
|
bnd = catch(:received_fake_call) do
|
38
|
-
fake_recipient.send(method_id, *fake_call_args)
|
39
|
+
fake_recipient.send(method_id, *fake_call_args, **fake_call_kwargs)
|
39
40
|
end
|
40
41
|
|
41
42
|
trace_point.disable
|
@@ -78,9 +78,23 @@ module Simple::Service
|
|
78
78
|
|
79
79
|
verify_required_args!(args, flags)
|
80
80
|
|
81
|
+
args = args.dup
|
82
|
+
flags = flags.dup
|
83
|
+
|
81
84
|
positionals = build_positional_arguments(args, flags)
|
85
|
+
|
86
|
+
if flags["args"].is_a?(Array)
|
87
|
+
positionals.concat flags.delete("args")
|
88
|
+
end
|
89
|
+
|
82
90
|
keywords = build_keyword_arguments(args.merge(flags))
|
83
91
|
|
92
|
+
# check for extra flags
|
93
|
+
unknown_flags = (flags.keys - keywords.keys.map(&:to_s))
|
94
|
+
unless unknown_flags.empty?
|
95
|
+
raise Simple::Service::UnknownFlagError.new(name, unknown_flags)
|
96
|
+
end
|
97
|
+
|
84
98
|
service_instance = Object.new
|
85
99
|
service_instance.extend service
|
86
100
|
|
@@ -102,7 +116,7 @@ module Simple::Service
|
|
102
116
|
missing_parameters = @required_names - args.keys - flags.keys
|
103
117
|
return if missing_parameters.empty?
|
104
118
|
|
105
|
-
raise ::Simple::Service::
|
119
|
+
raise ::Simple::Service::MissingArgumentError.new(self, missing_parameters)
|
106
120
|
end
|
107
121
|
|
108
122
|
# Enumerating all parameters it puts all named parameters into a Hash
|
@@ -133,9 +147,9 @@ module Simple::Service
|
|
133
147
|
def build_positional_arguments(args, flags)
|
134
148
|
positionals = positional_names.each_with_object([]) do |parameter_name, ary|
|
135
149
|
if args.key?(parameter_name)
|
136
|
-
ary << args
|
150
|
+
ary << args.delete(parameter_name)
|
137
151
|
elsif flags.key?(parameter_name)
|
138
|
-
ary << flags
|
152
|
+
ary << flags.delete(parameter_name)
|
139
153
|
end
|
140
154
|
end
|
141
155
|
|
@@ -143,9 +157,9 @@ module Simple::Service
|
|
143
157
|
# It is always optional - but if it exists it must be an Array.
|
144
158
|
if variadic_parameter
|
145
159
|
value = if args.key?(variadic_parameter.name)
|
146
|
-
args
|
160
|
+
args.delete(variadic_parameter.name)
|
147
161
|
elsif flags.key?(variadic_parameter.name)
|
148
|
-
flags
|
162
|
+
flags.delete(variadic_parameter.name)
|
149
163
|
end
|
150
164
|
|
151
165
|
positionals.concat(value) if value
|
@@ -169,7 +183,7 @@ module Simple::Service
|
|
169
183
|
ary = ary[0..positional_names.length]
|
170
184
|
|
171
185
|
if !extra_arguments.empty? && !variadic_parameter
|
172
|
-
raise ::Simple::Service::
|
186
|
+
raise ::Simple::Service::ExtraArgumentError.new(self, extra_arguments)
|
173
187
|
end
|
174
188
|
|
175
189
|
existing_positional_names = positional_names
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Simple::Service
|
2
2
|
# Will be raised by ::Simple::Service.action.
|
3
|
-
class
|
3
|
+
class NoSuchActionError < ::ArgumentError
|
4
4
|
attr_reader :service, :name
|
5
5
|
|
6
6
|
def initialize(service, name)
|
@@ -18,7 +18,7 @@ module Simple::Service
|
|
18
18
|
class ArgumentError < ::ArgumentError
|
19
19
|
end
|
20
20
|
|
21
|
-
class
|
21
|
+
class MissingArgumentError < ArgumentError
|
22
22
|
attr_reader :action
|
23
23
|
attr_reader :parameters
|
24
24
|
|
@@ -32,7 +32,7 @@ module Simple::Service
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
class
|
35
|
+
class ExtraArgumentError < ArgumentError
|
36
36
|
attr_reader :action
|
37
37
|
attr_reader :arguments
|
38
38
|
|
@@ -42,8 +42,22 @@ module Simple::Service
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def to_s
|
45
|
-
str =
|
46
|
-
"#{action}: extra argument(s) #{str}"
|
45
|
+
str = arguments.map(&:inspect).join(", ")
|
46
|
+
"#{action}: extra argument(s): #{str}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class UnknownFlagError < ExtraArgumentError
|
51
|
+
attr_reader :flags
|
52
|
+
|
53
|
+
def initialize(action, flags)
|
54
|
+
@flags = flags
|
55
|
+
super(action, flags)
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
inspected_flags = flags.map { |flag| "--#{flag}" }.join(", ")
|
60
|
+
"#{action}: unknown flag(s): #{inspected_flags}"
|
47
61
|
end
|
48
62
|
end
|
49
63
|
|
data/lib/simple/service.rb
CHANGED
@@ -86,7 +86,7 @@ module Simple::Service
|
|
86
86
|
|
87
87
|
actions = self.actions(service)
|
88
88
|
actions[name] || begin
|
89
|
-
raise ::Simple::Service::
|
89
|
+
raise ::Simple::Service::NoSuchActionError.new(service, name)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -98,6 +98,14 @@ module Simple::Service
|
|
98
98
|
# As the main purpose of this module is to call services with outside data,
|
99
99
|
# the +.invoke+ action is usually preferred.
|
100
100
|
def self.invoke3(service, name, *args, **flags)
|
101
|
+
# The following checks if flags is empty. This might be intentional, but might also mean that
|
102
|
+
# the caller is sending in kwargs as last arguments of the args array.
|
103
|
+
#
|
104
|
+
# This is supported in 2.7.*, but no longer works with ruby 3.
|
105
|
+
if flags.empty? && args.last.is_a?(Hash)
|
106
|
+
flags = args.pop
|
107
|
+
end
|
108
|
+
|
101
109
|
flags = flags.transform_keys(&:to_s)
|
102
110
|
invoke service, name, args: args, flags: flags
|
103
111
|
end
|
data/simple-service.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
# executables are used for development purposes only
|
20
20
|
gem.executables = []
|
21
21
|
|
22
|
-
gem.required_ruby_version = '
|
22
|
+
gem.required_ruby_version = '>= 2.5'
|
23
23
|
|
24
24
|
gem.add_dependency "expectation", "~> 1"
|
25
25
|
gem.add_dependency "simple-immutable", "~> 1", ">= 1.1"
|
@@ -6,16 +6,6 @@ describe "Simple::Service.invoke3" do
|
|
6
6
|
let(:service) { InvokeTestService }
|
7
7
|
let(:action) { nil }
|
8
8
|
|
9
|
-
# a shortcut
|
10
|
-
def invoke3!(*args, **keywords)
|
11
|
-
@actual = ::Simple::Service.invoke3(service, action, *args, **keywords)
|
12
|
-
# rescue ::StandardError => e
|
13
|
-
rescue ::Simple::Service::ArgumentError => e
|
14
|
-
@actual = e
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :actual
|
18
|
-
|
19
9
|
# when calling #invoke3 using positional arguments they will be matched against
|
20
10
|
# positional arguments of the invoke3d method - but they will not be matched
|
21
11
|
# against named arguments.
|
@@ -37,33 +27,34 @@ describe "Simple::Service.invoke3" do
|
|
37
27
|
|
38
28
|
context "calling without args" do
|
39
29
|
it "runs the action" do
|
40
|
-
invoke3
|
30
|
+
actual = ::Simple::Service.invoke3(service, action)
|
41
31
|
expect(actual).to eq("service2 return")
|
42
32
|
end
|
43
33
|
end
|
44
34
|
|
45
35
|
context "calling with extra positional args" do
|
46
36
|
it "raises ExtraArguments" do
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
expect {
|
38
|
+
::Simple::Service.invoke3(service, action, "foo", "bar")
|
39
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError, /"foo", "bar"/)
|
50
40
|
end
|
51
41
|
end
|
52
42
|
|
53
43
|
context "calling with extra named args" do
|
54
|
-
it "
|
55
|
-
|
56
|
-
|
44
|
+
it "raises an ExtraArguments error" do
|
45
|
+
expect {
|
46
|
+
::Simple::Service.invoke3(service, action, foo: "foo", bar: "bar")
|
47
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
57
48
|
end
|
58
49
|
end
|
59
50
|
|
60
51
|
context "calling with an additional hash arg" do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
52
|
+
it "ignores extra args" do
|
53
|
+
expect {
|
54
|
+
args = []
|
55
|
+
args.push foo: "foo", bar: "bar"
|
56
|
+
::Simple::Service.invoke3(service, action, *args)
|
57
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
67
58
|
end
|
68
59
|
end
|
69
60
|
end
|
@@ -79,44 +70,48 @@ describe "Simple::Service.invoke3" do
|
|
79
70
|
|
80
71
|
context "without args" do
|
81
72
|
it "raises MissingArguments" do
|
82
|
-
|
83
|
-
|
73
|
+
expect {
|
74
|
+
::Simple::Service.invoke3(service, action)
|
75
|
+
}.to raise_error(::Simple::Service::MissingArgumentError)
|
84
76
|
end
|
85
77
|
end
|
86
78
|
|
87
79
|
context "with the required number of args" do
|
88
80
|
it "runs" do
|
89
|
-
invoke3
|
81
|
+
actual = ::Simple::Service.invoke3(service, action, "foo", "bar")
|
90
82
|
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
|
91
83
|
end
|
92
84
|
end
|
93
85
|
|
94
86
|
context "with the allowed number of args" do
|
95
87
|
it "runs" do
|
96
|
-
invoke3
|
88
|
+
actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "number4")
|
97
89
|
expect(actual).to eq(%w[foo bar baz number4])
|
98
90
|
end
|
99
91
|
end
|
100
92
|
|
101
93
|
context "with more than the allowed number of args" do
|
102
94
|
it "raises ExtraArguments" do
|
103
|
-
|
104
|
-
|
95
|
+
expect {
|
96
|
+
::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "number4", "extra")
|
97
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
105
98
|
end
|
106
99
|
end
|
107
100
|
|
108
101
|
context "calling with extra named args" do
|
109
102
|
it "ignores extra args" do
|
110
|
-
|
111
|
-
|
103
|
+
expect {
|
104
|
+
::Simple::Service.invoke3(service, action, "foo", "bar", "baz", extra3: 3)
|
105
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
112
106
|
end
|
113
107
|
end
|
114
108
|
|
115
109
|
context "calling with an additional hash arg" do
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
110
|
+
it "raises ExtraArguments" do
|
111
|
+
expect {
|
112
|
+
args = ["foo", "bar", "baz", extra3: 3]
|
113
|
+
::Simple::Service.invoke3(service, action, *args)
|
114
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
120
115
|
end
|
121
116
|
end
|
122
117
|
end
|
@@ -132,36 +127,39 @@ describe "Simple::Service.invoke3" do
|
|
132
127
|
|
133
128
|
context "without args" do
|
134
129
|
it "raises MissingArguments" do
|
135
|
-
|
136
|
-
|
130
|
+
expect {
|
131
|
+
::Simple::Service.invoke3(service, action)
|
132
|
+
}.to raise_error(::Simple::Service::MissingArgumentError)
|
137
133
|
end
|
138
134
|
end
|
139
135
|
|
140
136
|
context "with the required number of args" do
|
141
137
|
it "runs" do
|
142
|
-
invoke3
|
138
|
+
actual = ::Simple::Service.invoke3(service, action, a: "foo", b: "bar")
|
143
139
|
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
|
144
140
|
end
|
145
141
|
end
|
146
142
|
|
147
143
|
context "with the allowed number of args" do
|
148
144
|
it "runs" do
|
149
|
-
invoke3
|
145
|
+
actual = ::Simple::Service.invoke3(service, action, a: "foo", b: "bar", c: "baz", e: "number4")
|
150
146
|
expect(actual).to eq(%w[foo bar baz number4])
|
151
147
|
end
|
152
148
|
end
|
153
149
|
|
154
150
|
context "with more than the allowed number of args" do
|
155
151
|
it "runs" do
|
156
|
-
|
157
|
-
|
152
|
+
expect {
|
153
|
+
::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "number4", "extra")
|
154
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
158
155
|
end
|
159
156
|
end
|
160
157
|
|
161
158
|
context "with extra named args" do
|
162
159
|
it "ignores extra args" do
|
163
|
-
|
164
|
-
|
160
|
+
expect {
|
161
|
+
::Simple::Service.invoke3(service, action, a: "foo", b: "bar", c: "baz", extra3: 3)
|
162
|
+
}.to raise_error(::Simple::Service::ArgumentError)
|
165
163
|
end
|
166
164
|
end
|
167
165
|
end
|
@@ -177,36 +175,39 @@ describe "Simple::Service.invoke3" do
|
|
177
175
|
|
178
176
|
context "without args" do
|
179
177
|
it "raises MissingArguments" do
|
180
|
-
|
181
|
-
|
178
|
+
expect {
|
179
|
+
::Simple::Service.invoke3(service, action)
|
180
|
+
}.to raise_error(::Simple::Service::MissingArgumentError)
|
182
181
|
end
|
183
182
|
end
|
184
183
|
|
185
184
|
context "with the required number of args" do
|
186
185
|
it "runs" do
|
187
|
-
invoke3
|
186
|
+
actual = ::Simple::Service.invoke3(service, action, "foo")
|
188
187
|
expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
|
189
188
|
end
|
190
189
|
end
|
191
190
|
|
192
191
|
context "with the allowed number of args" do
|
193
192
|
it "runs" do
|
194
|
-
invoke3
|
193
|
+
actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4")
|
195
194
|
expect(actual).to eq(%w[foo bar baz number4])
|
196
195
|
end
|
197
196
|
end
|
198
197
|
|
199
198
|
context "with more than the allowed number of args" do
|
200
|
-
it "
|
201
|
-
|
202
|
-
|
199
|
+
it "raises an ExtraArguments error" do
|
200
|
+
expect {
|
201
|
+
::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "extra", e: "number4")
|
202
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
206
|
context "with extra named args" do
|
207
|
-
it "
|
208
|
-
|
209
|
-
|
207
|
+
it "raises an ExtraArguments error" do
|
208
|
+
expect {
|
209
|
+
::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4", extra3: 3)
|
210
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
210
211
|
end
|
211
212
|
end
|
212
213
|
end
|
@@ -222,36 +223,38 @@ describe "Simple::Service.invoke3" do
|
|
222
223
|
|
223
224
|
context "without args" do
|
224
225
|
it "raises MissingArguments" do
|
225
|
-
|
226
|
-
|
226
|
+
expect {
|
227
|
+
::Simple::Service.invoke3(service, action)
|
228
|
+
}.to raise_error(::Simple::Service::MissingArgumentError)
|
227
229
|
end
|
228
230
|
end
|
229
231
|
|
230
232
|
context "with the required number of args" do
|
231
233
|
it "runs" do
|
232
|
-
invoke3
|
234
|
+
actual = ::Simple::Service.invoke3(service, action, "foo")
|
233
235
|
expect(actual).to eq(["foo", "queen bee", [], 2.781])
|
234
236
|
end
|
235
237
|
end
|
236
238
|
|
237
239
|
context "with the allowed number of args" do
|
238
240
|
it "runs" do
|
239
|
-
invoke3
|
241
|
+
actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4")
|
240
242
|
expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
|
241
243
|
end
|
242
244
|
end
|
243
245
|
|
244
246
|
context "with more than the allowed number of args" do
|
245
247
|
it "runs" do
|
246
|
-
invoke3
|
248
|
+
actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "extra", e: "number4")
|
247
249
|
expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
|
248
250
|
end
|
249
251
|
end
|
250
252
|
|
251
253
|
context "with extra named args" do
|
252
|
-
it "
|
253
|
-
|
254
|
-
|
254
|
+
it "raises an ExtraArguments error" do
|
255
|
+
expect {
|
256
|
+
::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4", extra3: 3)
|
257
|
+
}.to raise_error(::Simple::Service::ExtraArgumentError)
|
255
258
|
end
|
256
259
|
end
|
257
260
|
end
|
@@ -5,16 +5,6 @@ describe "Simple::Service.invoke" do
|
|
5
5
|
let(:service) { InvokeTestService }
|
6
6
|
let(:action) { nil }
|
7
7
|
|
8
|
-
# a shortcut
|
9
|
-
def invoke!(args: {}, flags: {})
|
10
|
-
@actual = ::Simple::Service.invoke(service, action, args: args, flags: flags)
|
11
|
-
# rescue ::StandardError => e
|
12
|
-
rescue ::Simple::Service::ArgumentError => e
|
13
|
-
@actual = e
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_reader :actual
|
17
|
-
|
18
8
|
context "calling an action w/o parameters" do
|
19
9
|
# reminder: this is the definition of no_params
|
20
10
|
#
|
@@ -26,22 +16,23 @@ describe "Simple::Service.invoke" do
|
|
26
16
|
|
27
17
|
context "calling without args" do
|
28
18
|
it "runs the action" do
|
29
|
-
invoke
|
19
|
+
actual = ::Simple::Service.invoke(service, action, args: {}, flags: {})
|
30
20
|
expect(actual).to eq("service2 return")
|
31
21
|
end
|
32
22
|
end
|
33
23
|
|
34
24
|
context "calling with extra named args" do
|
35
25
|
it "ignores extra args" do
|
36
|
-
invoke
|
26
|
+
actual = ::Simple::Service.invoke(service, action, args: { "foo" => "foo", "bar" => "bar" }, flags: {})
|
37
27
|
expect(actual).to eq("service2 return")
|
38
28
|
end
|
39
29
|
end
|
40
30
|
|
41
31
|
context "calling with extra flags" do
|
42
|
-
it "
|
43
|
-
|
44
|
-
|
32
|
+
it "raises an error" do
|
33
|
+
expect {
|
34
|
+
::Simple::Service.invoke(service, action, args: {}, flags: { "foo" => "foo", "bar" => "bar" })
|
35
|
+
}.to raise_error(::Simple::Service::UnknownFlagError)
|
45
36
|
end
|
46
37
|
end
|
47
38
|
end
|
@@ -57,36 +48,36 @@ describe "Simple::Service.invoke" do
|
|
57
48
|
|
58
49
|
context "without args" do
|
59
50
|
it "raises MissingArguments" do
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
expect {
|
52
|
+
::Simple::Service.invoke(service, action, args: {}, flags: {})
|
53
|
+
}.to raise_exception(::Simple::Service::MissingArgumentError, /\ba, b\b/)
|
63
54
|
end
|
64
55
|
end
|
65
56
|
|
66
57
|
context "with the required number of args" do
|
67
58
|
it "runs" do
|
68
|
-
invoke
|
59
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar" }, flags: {})
|
69
60
|
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
|
70
61
|
end
|
71
62
|
end
|
72
63
|
|
73
64
|
context "with the required number of args and flags" do
|
74
|
-
it "merges flags and args to provide arguments" do
|
75
|
-
invoke
|
65
|
+
it "merges flags and args to provide variadic arguments" do
|
66
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo" }, flags: { "b" => "bar" })
|
76
67
|
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
|
77
68
|
end
|
78
69
|
end
|
79
70
|
|
80
71
|
context "with the allowed number of args" do
|
81
72
|
it "runs" do
|
82
|
-
invoke
|
73
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4" }, flags: {})
|
83
74
|
expect(actual).to eq(%w[foo bar baz number4])
|
84
75
|
end
|
85
76
|
end
|
86
77
|
|
87
78
|
context "calling with extra named args" do
|
88
79
|
it "ignores extra args" do
|
89
|
-
invoke
|
80
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4", "extra3" => 3 }, flags: {})
|
90
81
|
expect(actual).to eq(%w[foo bar baz number4])
|
91
82
|
end
|
92
83
|
end
|
@@ -103,29 +94,29 @@ describe "Simple::Service.invoke" do
|
|
103
94
|
|
104
95
|
context "without args" do
|
105
96
|
it "raises MissingArguments" do
|
106
|
-
|
107
|
-
|
108
|
-
|
97
|
+
expect {
|
98
|
+
::Simple::Service.invoke(service, action, args: {}, flags: {})
|
99
|
+
}.to raise_error(::Simple::Service::MissingArgumentError, /\ba, b\b/)
|
109
100
|
end
|
110
101
|
end
|
111
102
|
|
112
103
|
context "with the required number of args" do
|
113
104
|
it "runs" do
|
114
|
-
invoke
|
105
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar" }, flags: {})
|
115
106
|
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
|
116
107
|
end
|
117
108
|
end
|
118
109
|
|
119
110
|
context "with the allowed number of args" do
|
120
111
|
it "runs" do
|
121
|
-
invoke
|
112
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4" }, flags: {})
|
122
113
|
expect(actual).to eq(%w[foo bar baz number4])
|
123
114
|
end
|
124
115
|
end
|
125
116
|
|
126
117
|
context "with extra named args" do
|
127
118
|
it "ignores extra args" do
|
128
|
-
invoke
|
119
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "c" => "baz", "extra3" => 3 }, flags: {})
|
129
120
|
expect(actual).to eq(["foo", "bar", "baz", 2.781])
|
130
121
|
end
|
131
122
|
end
|
@@ -142,28 +133,29 @@ describe "Simple::Service.invoke" do
|
|
142
133
|
|
143
134
|
context "without args" do
|
144
135
|
it "raises MissingArguments" do
|
145
|
-
|
146
|
-
|
136
|
+
expect {
|
137
|
+
::Simple::Service.invoke(service, action, args: {}, flags: {})
|
138
|
+
}.to raise_error(::Simple::Service::MissingArgumentError)
|
147
139
|
end
|
148
140
|
end
|
149
141
|
|
150
142
|
context "with the required number of args" do
|
151
143
|
it "runs" do
|
152
|
-
invoke
|
144
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo" }, flags: {})
|
153
145
|
expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
|
154
146
|
end
|
155
147
|
end
|
156
148
|
|
157
149
|
context "with the allowed number of args" do
|
158
150
|
it "runs" do
|
159
|
-
invoke
|
151
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4" }, flags: {})
|
160
152
|
expect(actual).to eq(%w[foo bar baz number4])
|
161
153
|
end
|
162
154
|
end
|
163
155
|
|
164
156
|
context "with extra named args" do
|
165
157
|
it "ignores extra args" do
|
166
|
-
invoke
|
158
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4", "extra3" => 3 }, flags: {})
|
167
159
|
expect(actual).to eq(["foo", "bar", "baz", "number4"])
|
168
160
|
end
|
169
161
|
end
|
@@ -180,33 +172,34 @@ describe "Simple::Service.invoke" do
|
|
180
172
|
|
181
173
|
context "without args" do
|
182
174
|
it "raises MissingArguments" do
|
183
|
-
|
184
|
-
|
175
|
+
expect {
|
176
|
+
::Simple::Service.invoke(service, action, args: {}, flags: {})
|
177
|
+
}.to raise_error(::Simple::Service::MissingArgumentError)
|
185
178
|
end
|
186
179
|
end
|
187
180
|
|
188
181
|
context "with the required number of args" do
|
189
182
|
it "runs" do
|
190
|
-
invoke
|
183
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo" }, flags: {})
|
191
184
|
expect(actual).to eq(["foo", "queen bee", [], 2.781])
|
192
185
|
end
|
193
186
|
end
|
194
187
|
|
195
188
|
context "with the allowed number of args" do
|
196
189
|
it "runs" do
|
197
|
-
invoke
|
190
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "args" => ["baz"] }, flags: { "e" => "number4" })
|
198
191
|
expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
|
199
192
|
end
|
200
193
|
end
|
201
194
|
|
202
195
|
context "with variadic args" do
|
203
196
|
it "sends the variadic args from the args: parameter" do
|
204
|
-
invoke
|
197
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar", "args" => ["baz", "extra"] }, flags: { "e" => "number4" })
|
205
198
|
expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
|
206
199
|
end
|
207
200
|
|
208
201
|
it "sends the variadic args from the flags: parameter" do
|
209
|
-
invoke
|
202
|
+
actual = ::Simple::Service.invoke(service, action, args: { "a" => "foo", "b" => "bar" }, flags: { "args" => ["baz", "extra"], "e" => "number4" })
|
210
203
|
expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
|
211
204
|
end
|
212
205
|
end
|
@@ -216,13 +209,13 @@ describe "Simple::Service.invoke" do
|
|
216
209
|
it "raises ArgumentError" do
|
217
210
|
hsh = { a: "foo", "b" => "KJH" }
|
218
211
|
|
219
|
-
expect
|
220
|
-
invoke
|
221
|
-
|
212
|
+
expect {
|
213
|
+
::Simple::Service.invoke(service, action, args: hsh, flags: {})
|
214
|
+
}.to raise_error(Expectation::Matcher::Mismatch)
|
222
215
|
|
223
|
-
expect
|
224
|
-
invoke
|
225
|
-
|
216
|
+
expect {
|
217
|
+
::Simple::Service.invoke(service, action, args: {}, flags: hsh)
|
218
|
+
}.to raise_error(Expectation::Matcher::Mismatch)
|
226
219
|
end
|
227
220
|
end
|
228
221
|
end
|
@@ -47,11 +47,11 @@ describe "Simple::Service" do
|
|
47
47
|
|
48
48
|
describe "Simple::Service::NoSuchAction" do
|
49
49
|
it "does not inherit from Simple::Service::ArgumentError" do
|
50
|
-
expect(Simple::Service::
|
50
|
+
expect(Simple::Service::NoSuchActionError < Simple::Service::ArgumentError).to be_falsey
|
51
51
|
end
|
52
52
|
|
53
53
|
it "inherits from ArgumentError" do
|
54
|
-
expect(Simple::Service::
|
54
|
+
expect(Simple::Service::NoSuchActionError < ::ArgumentError).to eq true
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,55 +59,40 @@ describe "Simple::Service" do
|
|
59
59
|
it "raises a NoSuchAction error" do
|
60
60
|
expect do
|
61
61
|
Simple::Service.action(service, :no_such_service)
|
62
|
-
end.to raise_error(Simple::Service::
|
62
|
+
end.to raise_error(Simple::Service::NoSuchActionError, /No such action :no_such_service/)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe ".invoke3" do
|
68
|
-
def invoke3
|
69
|
-
Simple::Service.invoke3(service, :service1, "my_a", "my_b", d: "my_d")
|
70
|
-
end
|
71
|
-
|
72
68
|
it "calls Action#invoke with the right arguments" do
|
73
69
|
action = Simple::Service.actions(service)[:service1]
|
74
70
|
expect(action).to receive(:invoke).with(args: ["my_a", "my_b"], flags: { "d" => "my_d" })
|
75
71
|
|
76
|
-
invoke3
|
72
|
+
Simple::Service.invoke3(service, :service1, "my_a", "my_b", d: "my_d")
|
77
73
|
end
|
78
74
|
end
|
79
75
|
|
80
76
|
describe ".invoke" do
|
81
77
|
context "with a args array" do
|
82
|
-
def invoke
|
83
|
-
Simple::Service.invoke(service, :service1, args: ["my_a", "my_b"], flags: { "d" => "my_d" })
|
84
|
-
end
|
85
|
-
|
86
78
|
it "calls Action#invoke with the right arguments" do
|
87
79
|
action = Simple::Service.actions(service)[:service1]
|
88
80
|
expect(action).to receive(:invoke).with(args: ["my_a", "my_b"], flags: { "d" => "my_d" }).and_call_original
|
89
81
|
|
90
|
-
invoke
|
82
|
+
Simple::Service.invoke(service, :service1, args: ["my_a", "my_b"], flags: { "d" => "my_d" })
|
91
83
|
end
|
92
84
|
end
|
93
85
|
end
|
94
86
|
|
95
87
|
describe "documentation example" do
|
96
|
-
def invoke(*args, **flags)
|
97
|
-
Simple::Service.invoke(SpecTestService, :foo, *args, **flags)
|
98
|
-
end
|
99
|
-
|
100
|
-
def invoke3(*args, **flags)
|
101
|
-
Simple::Service.invoke3(SpecTestService, :foo, *args, **flags)
|
102
|
-
end
|
103
|
-
|
104
88
|
it "calls Action#invoke with the right arguments" do
|
105
89
|
expected = ["bar-value", "baz-value"]
|
106
90
|
|
107
|
-
expect(
|
108
|
-
expect(
|
109
|
-
|
110
|
-
expect(
|
91
|
+
expect(Simple::Service.invoke(SpecTestService, :foo, args: ["bar-value"], flags: { "baz" => "baz-value" })).to eq(expected)
|
92
|
+
expect(Simple::Service.invoke(SpecTestService, :foo, args: { "bar" => "bar-value", "baz" => "baz-value" })).to eq(expected)
|
93
|
+
|
94
|
+
expect(Simple::Service.invoke3(SpecTestService, :foo, "bar-value", baz: "baz-value")).to eq(expected)
|
95
|
+
expect(Simple::Service.invoke3(SpecTestService, :foo, bar: "bar-value", baz: "baz-value")).to eq(expected)
|
111
96
|
end
|
112
97
|
end
|
113
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: expectation
|
@@ -50,6 +50,7 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
+
- ".github/workflows/rspec.yaml"
|
53
54
|
- ".gitignore"
|
54
55
|
- ".rubocop.yml"
|
55
56
|
- ".tm_properties"
|
@@ -130,13 +131,13 @@ files:
|
|
130
131
|
homepage: http://github.com/radiospiel/simple-service
|
131
132
|
licenses: []
|
132
133
|
metadata: {}
|
133
|
-
post_install_message:
|
134
|
+
post_install_message:
|
134
135
|
rdoc_options: []
|
135
136
|
require_paths:
|
136
137
|
- lib
|
137
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
139
|
requirements:
|
139
|
-
- - "
|
140
|
+
- - ">="
|
140
141
|
- !ruby/object:Gem::Version
|
141
142
|
version: '2.5'
|
142
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -145,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
146
|
- !ruby/object:Gem::Version
|
146
147
|
version: '0'
|
147
148
|
requirements: []
|
148
|
-
rubygems_version: 3.
|
149
|
-
signing_key:
|
149
|
+
rubygems_version: 3.2.3
|
150
|
+
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Pretty simple and somewhat abstract service description
|
152
153
|
test_files:
|