simple-service 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.rubocop.yml +10 -2
  4. data/Gemfile +3 -1
  5. data/Makefile +7 -11
  6. data/README.md +67 -2
  7. data/TODO.txt +3 -0
  8. data/VERSION +1 -1
  9. data/doc/Simple/Service/Action/Comment/Extractor.html +347 -0
  10. data/doc/Simple/Service/Action/Comment.html +451 -0
  11. data/doc/Simple/Service/Action/MethodReflection.html +285 -0
  12. data/doc/Simple/Service/Action/Parameter.html +816 -0
  13. data/doc/Simple/Service/Action.html +923 -0
  14. data/doc/Simple/Service/ArgumentError.html +128 -0
  15. data/doc/Simple/Service/ClassMethods.html +187 -0
  16. data/doc/Simple/Service/Context.html +379 -0
  17. data/doc/Simple/Service/ContextMissingError.html +124 -0
  18. data/doc/Simple/Service/ContextReadOnlyError.html +206 -0
  19. data/doc/Simple/Service/ExtraArguments.html +428 -0
  20. data/doc/Simple/Service/GemHelper.html +190 -0
  21. data/doc/Simple/Service/MissingArguments.html +426 -0
  22. data/doc/Simple/Service/NoSuchAction.html +433 -0
  23. data/doc/Simple/Service.html +865 -0
  24. data/doc/Simple.html +117 -0
  25. data/doc/_index.html +274 -0
  26. data/doc/class_list.html +51 -0
  27. data/doc/css/common.css +1 -0
  28. data/doc/css/full_list.css +58 -0
  29. data/doc/css/style.css +496 -0
  30. data/doc/file.README.html +146 -0
  31. data/doc/file.TODO.html +70 -0
  32. data/doc/file_list.html +61 -0
  33. data/doc/frames.html +17 -0
  34. data/doc/index.html +146 -0
  35. data/doc/js/app.js +303 -0
  36. data/doc/js/full_list.js +216 -0
  37. data/doc/js/jquery.js +4 -0
  38. data/doc/method_list.html +483 -0
  39. data/doc/top-level-namespace.html +110 -0
  40. data/lib/simple/service/action/comment.rb +2 -2
  41. data/lib/simple/service/action/method_reflection.rb +1 -1
  42. data/lib/simple/service/action/parameter.rb +1 -1
  43. data/lib/simple/service/action.rb +34 -46
  44. data/lib/simple/service/errors.rb +4 -3
  45. data/lib/simple/service/version.rb +2 -2
  46. data/lib/simple/service.rb +109 -34
  47. data/lib/simple/workflow/context.rb +105 -0
  48. data/lib/simple/workflow/current_context.rb +33 -0
  49. data/lib/simple/workflow/reloader.rb +84 -0
  50. data/lib/simple/workflow/rspec_helper.rb +15 -0
  51. data/lib/simple/workflow.rb +96 -0
  52. data/lib/simple-workflow.rb +3 -0
  53. data/scripts/test +2 -0
  54. data/simple-service.gemspec +1 -0
  55. data/spec/simple/service/action_invoke3_spec.rb +258 -0
  56. data/spec/simple/service/action_invoke_spec.rb +49 -87
  57. data/spec/simple/service/service_spec.rb +40 -32
  58. data/spec/simple/workflow/context_spec.rb +90 -0
  59. data/spec/simple/workflow/current_context_spec.rb +41 -0
  60. data/spec/simple/workflow/reloader_spec/example1.rb +10 -0
  61. data/spec/simple/workflow/reloader_spec/example2.rb +7 -0
  62. data/spec/simple/workflow/reloader_spec.rb +48 -0
  63. data/spec/spec_helper.rb +2 -1
  64. data/spec/support/spec_services.rb +8 -2
  65. metadata +74 -9
  66. data/lib/simple/service/action/indie_hash.rb +0 -37
  67. data/lib/simple/service/context.rb +0 -94
  68. data/spec/simple/service/action_invoke2_spec.rb +0 -166
  69. data/spec/simple/service/context_spec.rb +0 -69
@@ -0,0 +1,96 @@
1
+ require "simple/service"
2
+
3
+ require_relative "workflow/context"
4
+ require_relative "workflow/current_context"
5
+ require_relative "workflow/reloader"
6
+
7
+ if defined?(RSpec)
8
+ require_relative "workflow/rspec_helper"
9
+ end
10
+
11
+ module Simple::Workflow
12
+ class ContextMissingError < ::StandardError
13
+ def to_s
14
+ "Simple::Workflow.current_context not initialized; remember to call Simple::Workflow.with_context/1"
15
+ end
16
+ end
17
+
18
+ module HelperMethods
19
+ def invoke(*args, **kwargs)
20
+ Simple::Workflow.invoke(self, *args, **kwargs)
21
+ end
22
+ end
23
+
24
+ module InstanceHelperMethods
25
+ private
26
+
27
+ def current_context
28
+ Simple::Workflow.current_context
29
+ end
30
+ end
31
+
32
+ module ModuleMethods
33
+ def register_workflow(mod)
34
+ expect! mod => Module
35
+
36
+ mod.extend ::Simple::Workflow::HelperMethods
37
+ mod.include ::Simple::Workflow::InstanceHelperMethods
38
+ mod.extend mod
39
+ mod.include Simple::Service
40
+ end
41
+
42
+ def reload_on_invocation?
43
+ !!@reload_on_invocation
44
+ end
45
+
46
+ def reload_on_invocation!
47
+ @reload_on_invocation = true
48
+ end
49
+
50
+ def invoke(workflow, *args, **kwargs)
51
+ # This call to Simple::Workflow.current_context raises a ContextMissingError
52
+ # if the context is not set.
53
+ _ = ::Simple::Workflow.current_context
54
+
55
+ expect! workflow => [Module, String]
56
+
57
+ workflow_module = lookup_workflow!(workflow)
58
+
59
+ # We will reload workflow modules only once per invocation.
60
+ if Simple::Workflow.reload_on_invocation?
61
+ Simple::Workflow.current_context.reload!(workflow_module)
62
+ end
63
+
64
+ Simple::Service.invoke(workflow_module, :call, args: args, flags: kwargs.transform_keys(&:to_s))
65
+ end
66
+
67
+ private
68
+
69
+ def lookup_workflow!(workflow)
70
+ workflow_module = lookup_workflow(workflow)
71
+
72
+ verify_workflow! workflow_module
73
+
74
+ workflow_module
75
+ end
76
+
77
+ def lookup_workflow(workflow)
78
+ case workflow
79
+ when Module
80
+ workflow
81
+ when String
82
+ Object.const_get workflow
83
+ else
84
+ expect! workflow => [Module, String]
85
+ end
86
+ end
87
+
88
+ def verify_workflow!(workflow_module)
89
+ return if Simple::Service.actions(workflow_module).key?(:call)
90
+
91
+ raise ArgumentError, "#{workflow_module.name} is not a Simple::Workflow"
92
+ end
93
+ end
94
+
95
+ extend ModuleMethods
96
+ end
@@ -0,0 +1,3 @@
1
+ # rubocop:disable Naming/FileName
2
+
3
+ require "simple/workflow"
data/scripts/test ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ rspec "$@"
@@ -22,4 +22,5 @@ Gem::Specification.new do |gem|
22
22
  gem.required_ruby_version = '~> 2.5'
23
23
 
24
24
  gem.add_dependency "expectation", "~> 1"
25
+ gem.add_dependency "simple-immutable", "~> 1", ">= 1.1"
25
26
  end
@@ -0,0 +1,258 @@
1
+ # rubocop:disable Style/WordArray
2
+
3
+ require "spec_helper"
4
+
5
+ describe "Simple::Service.invoke3" do
6
+ let(:service) { InvokeTestService }
7
+ let(:action) { nil }
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
+ # when calling #invoke3 using positional arguments they will be matched against
20
+ # positional arguments of the invoke3d method - but they will not be matched
21
+ # against named arguments.
22
+ #
23
+ # When there are not enough positional arguments to match the number of required
24
+ # positional arguments of the method we raise an ArgumentError.
25
+ #
26
+ # When there are more positional arguments provided than the number accepted
27
+ # by the method we raise an ArgumentError.
28
+
29
+ context "calling an action w/o parameters" do
30
+ # reminder: this is the definition of no_params
31
+ #
32
+ # def no_params
33
+ # "service2 return"
34
+ # end
35
+
36
+ let(:action) { :no_params }
37
+
38
+ context "calling without args" do
39
+ it "runs the action" do
40
+ invoke3!
41
+ expect(actual).to eq("service2 return")
42
+ end
43
+ end
44
+
45
+ context "calling with extra positional args" do
46
+ it "raises ExtraArguments" do
47
+ invoke3!("foo", "bar")
48
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
49
+ expect(actual.to_s).to match(/"foo", "bar"/)
50
+ end
51
+ end
52
+
53
+ context "calling with extra named args" do
54
+ it "ignores extra args" do
55
+ invoke3!(foo: "foo", bar: "bar")
56
+ expect(actual).to eq("service2 return")
57
+ end
58
+ end
59
+
60
+ context "calling with an additional hash arg" do
61
+ xit "ignores extra args" do
62
+ args = []
63
+ args.push foo: "foo", bar: "bar"
64
+ invoke3!(*args)
65
+
66
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
67
+ end
68
+ end
69
+ end
70
+
71
+ context "calling an action w/positional parameters" do
72
+ # reminder: this is the definition of positional_params
73
+ #
74
+ # def positional_params(a, b, c = "speed-of-light", e = 2.781)
75
+ # [a, b, c, e]
76
+ # end
77
+
78
+ let(:action) { :positional_params }
79
+
80
+ context "without args" do
81
+ it "raises MissingArguments" do
82
+ invoke3!
83
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
84
+ end
85
+ end
86
+
87
+ context "with the required number of args" do
88
+ it "runs" do
89
+ invoke3!("foo", "bar")
90
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
91
+ end
92
+ end
93
+
94
+ context "with the allowed number of args" do
95
+ it "runs" do
96
+ invoke3!("foo", "bar", "baz", "number4")
97
+ expect(actual).to eq(%w[foo bar baz number4])
98
+ end
99
+ end
100
+
101
+ context "with more than the allowed number of args" do
102
+ it "raises ExtraArguments" do
103
+ invoke3!("foo", "bar", "baz", "number4", "extra")
104
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
105
+ end
106
+ end
107
+
108
+ context "calling with extra named args" do
109
+ it "ignores extra args" do
110
+ invoke3!("foo", "bar", "baz", extra3: 3)
111
+ expect(actual).to eq(["foo", "bar", "baz", 2.781])
112
+ end
113
+ end
114
+
115
+ context "calling with an additional hash arg" do
116
+ xit "raises ExtraArguments" do
117
+ args = ["foo", "bar", "baz", extra3: 3]
118
+ invoke3!(*args)
119
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
120
+ end
121
+ end
122
+ end
123
+
124
+ context "calling an action w/named parameters" do
125
+ # reminder: this is the definition of named_params
126
+ #
127
+ # def named_params(a:, b:, c: "speed-of-light", e: 2.781)
128
+ # [a, b, c, e]
129
+ # end
130
+
131
+ let(:action) { :named_params }
132
+
133
+ context "without args" do
134
+ it "raises MissingArguments" do
135
+ invoke3!
136
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
137
+ end
138
+ end
139
+
140
+ context "with the required number of args" do
141
+ it "runs" do
142
+ invoke3!(a: "foo", b: "bar")
143
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
144
+ end
145
+ end
146
+
147
+ context "with the allowed number of args" do
148
+ it "runs" do
149
+ invoke3!(a: "foo", b: "bar", c: "baz", e: "number4")
150
+ expect(actual).to eq(%w[foo bar baz number4])
151
+ end
152
+ end
153
+
154
+ context "with more than the allowed number of args" do
155
+ it "runs" do
156
+ invoke3!("foo", "bar", "baz", "number4", "extra")
157
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
158
+ end
159
+ end
160
+
161
+ context "with extra named args" do
162
+ it "ignores extra args" do
163
+ invoke3!(a: "foo", b: "bar", c: "baz", extra3: 3)
164
+ expect(actual).to eq(["foo", "bar", "baz", 2.781])
165
+ end
166
+ end
167
+ end
168
+
169
+ context "calling an action w/mixed and optional parameters" do
170
+ # reminder: this is the definition of named_params
171
+ #
172
+ # def mixed_optional_params(a, b = "default-b", c = "speed-of-light", e: 2.781)
173
+ # [a, b, c, e]
174
+ # end
175
+
176
+ let(:action) { :mixed_optional_params }
177
+
178
+ context "without args" do
179
+ it "raises MissingArguments" do
180
+ invoke3!
181
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
182
+ end
183
+ end
184
+
185
+ context "with the required number of args" do
186
+ it "runs" do
187
+ invoke3!("foo")
188
+ expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
189
+ end
190
+ end
191
+
192
+ context "with the allowed number of args" do
193
+ it "runs" do
194
+ invoke3!("foo", "bar", "baz", e: "number4")
195
+ expect(actual).to eq(%w[foo bar baz number4])
196
+ end
197
+ end
198
+
199
+ context "with more than the allowed number of args" do
200
+ it "runs" do
201
+ invoke3!("foo", "bar", "baz", "extra", e: "number4")
202
+ expect(actual).to be_a(::Simple::Service::ExtraArguments)
203
+ end
204
+ end
205
+
206
+ context "with extra named args" do
207
+ it "ignores extra args" do
208
+ invoke3!("foo", "bar", "baz", e: "number4", extra3: 3)
209
+ expect(actual).to eq(["foo", "bar", "baz", "number4"])
210
+ end
211
+ end
212
+ end
213
+
214
+ context "calling an action w/mixed and variadic parameters" do
215
+ # reminder: this is the definition of variadic_params
216
+ #
217
+ # def variadic_params(a, b = "queen bee", *args, e: 2.781)
218
+ # [a, b, args, e]
219
+ # end
220
+
221
+ let(:action) { :variadic_params }
222
+
223
+ context "without args" do
224
+ it "raises MissingArguments" do
225
+ invoke3!
226
+ expect(actual).to be_a(::Simple::Service::MissingArguments)
227
+ end
228
+ end
229
+
230
+ context "with the required number of args" do
231
+ it "runs" do
232
+ invoke3!("foo")
233
+ expect(actual).to eq(["foo", "queen bee", [], 2.781])
234
+ end
235
+ end
236
+
237
+ context "with the allowed number of args" do
238
+ it "runs" do
239
+ invoke3!("foo", "bar", "baz", e: "number4")
240
+ expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
241
+ end
242
+ end
243
+
244
+ context "with more than the allowed number of args" do
245
+ it "runs" do
246
+ invoke3!("foo", "bar", "baz", "extra", e: "number4")
247
+ expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
248
+ end
249
+ end
250
+
251
+ context "with extra named args" do
252
+ it "ignores extra args" do
253
+ invoke3!("foo", "bar", "baz", e: "number4", extra3: 3)
254
+ expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
255
+ end
256
+ end
257
+ end
258
+ end
@@ -1,22 +1,13 @@
1
1
  # rubocop:disable Style/WordArray
2
-
3
2
  require "spec_helper"
4
3
 
5
4
  describe "Simple::Service.invoke" do
6
- # the context to use in the around hook below. By default this is nil -
7
- # which gives us an empty context.
8
- let(:context) { nil }
9
-
10
- around do |example|
11
- ::Simple::Service.with_context(context) { example.run }
12
- end
13
-
14
5
  let(:service) { InvokeTestService }
15
6
  let(:action) { nil }
16
7
 
17
8
  # a shortcut
18
- def invoke!(*args, **keywords)
19
- @actual = ::Simple::Service.invoke(service, action, *args, **keywords)
9
+ def invoke!(args: {}, flags: {})
10
+ @actual = ::Simple::Service.invoke(service, action, args: args, flags: flags)
20
11
  # rescue ::StandardError => e
21
12
  rescue ::Simple::Service::ArgumentError => e
22
13
  @actual = e
@@ -24,16 +15,6 @@ describe "Simple::Service.invoke" do
24
15
 
25
16
  attr_reader :actual
26
17
 
27
- # when calling #invoke using positional arguments they will be matched against
28
- # positional arguments of the invoked method - but they will not be matched
29
- # against named arguments.
30
- #
31
- # When there are not enough positional arguments to match the number of required
32
- # positional arguments of the method we raise an ArgumentError.
33
- #
34
- # When there are more positional arguments provided than the number accepted
35
- # by the method we raise an ArgumentError.
36
-
37
18
  context "calling an action w/o parameters" do
38
19
  # reminder: this is the definition of no_params
39
20
  #
@@ -50,28 +31,17 @@ describe "Simple::Service.invoke" do
50
31
  end
51
32
  end
52
33
 
53
- context "calling with extra positional args" do
54
- it "raises ExtraArguments" do
55
- invoke!("foo", "bar")
56
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
57
- expect(actual.to_s).to match(/"foo", "bar"/)
58
- end
59
- end
60
-
61
34
  context "calling with extra named args" do
62
35
  it "ignores extra args" do
63
- invoke!(foo: "foo", bar: "bar")
36
+ invoke!(args: { "foo" => "foo", "bar" => "bar" })
64
37
  expect(actual).to eq("service2 return")
65
38
  end
66
39
  end
67
40
 
68
- context "calling with an additional hash arg" do
69
- xit "ignores extra args" do
70
- args = []
71
- args.push foo: "foo", bar: "bar"
72
- invoke!(*args)
73
-
74
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
41
+ context "calling with extra flags" do
42
+ it "ignores extra args" do
43
+ invoke!(flags: { "foo" => "foo", "bar" => "bar" })
44
+ expect(actual).to eq("service2 return")
75
45
  end
76
46
  end
77
47
  end
@@ -89,42 +59,35 @@ describe "Simple::Service.invoke" do
89
59
  it "raises MissingArguments" do
90
60
  invoke!
91
61
  expect(actual).to be_a(::Simple::Service::MissingArguments)
62
+ expect(actual.to_s).to match(/\ba, b\b/)
92
63
  end
93
64
  end
94
65
 
95
66
  context "with the required number of args" do
96
67
  it "runs" do
97
- invoke!("foo", "bar")
68
+ invoke!(args: { "a" => "foo", "b" => "bar" })
98
69
  expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
99
70
  end
100
71
  end
101
72
 
102
- context "with the allowed number of args" do
103
- it "runs" do
104
- invoke!("foo", "bar", "baz", "number4")
105
- expect(actual).to eq(%w[foo bar baz number4])
73
+ context "with the required number of args and flags" do
74
+ it "merges flags and args to provide arguments" do
75
+ invoke!(args: { "a" => "foo" }, flags: { "b" => "bar" })
76
+ expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
106
77
  end
107
78
  end
108
79
 
109
- context "with more than the allowed number of args" do
110
- it "raises ExtraArguments" do
111
- invoke!("foo", "bar", "baz", "number4", "extra")
112
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
80
+ context "with the allowed number of args" do
81
+ it "runs" do
82
+ invoke!(args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4" })
83
+ expect(actual).to eq(%w[foo bar baz number4])
113
84
  end
114
85
  end
115
86
 
116
87
  context "calling with extra named args" do
117
88
  it "ignores extra args" do
118
- invoke!("foo", "bar", "baz", extra3: 3)
119
- expect(actual).to eq(["foo", "bar", "baz", 2.781])
120
- end
121
- end
122
-
123
- context "calling with an additional hash arg" do
124
- xit "raises ExtraArguments" do
125
- args = ["foo", "bar", "baz", extra3: 3]
126
- invoke!(*args)
127
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
89
+ invoke!(args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4", "extra3" => 3 })
90
+ expect(actual).to eq(%w[foo bar baz number4])
128
91
  end
129
92
  end
130
93
  end
@@ -132,7 +95,7 @@ describe "Simple::Service.invoke" do
132
95
  context "calling an action w/named parameters" do
133
96
  # reminder: this is the definition of named_params
134
97
  #
135
- # def named_params(a:, b:, c: "speed-of-light", e: 2.781)
98
+ # def named_params(a:, b:, "c" => "speed-of-light", e: 2.781)
136
99
  # [a, b, c, e]
137
100
  # end
138
101
 
@@ -142,33 +105,27 @@ describe "Simple::Service.invoke" do
142
105
  it "raises MissingArguments" do
143
106
  invoke!
144
107
  expect(actual).to be_a(::Simple::Service::MissingArguments)
108
+ expect(actual.to_s).to match(/\ba, b\b/)
145
109
  end
146
110
  end
147
111
 
148
112
  context "with the required number of args" do
149
113
  it "runs" do
150
- invoke!(a: "foo", b: "bar")
114
+ invoke!(args: { "a" => "foo", "b" => "bar" })
151
115
  expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
152
116
  end
153
117
  end
154
118
 
155
119
  context "with the allowed number of args" do
156
120
  it "runs" do
157
- invoke!(a: "foo", b: "bar", c: "baz", e: "number4")
121
+ invoke!(args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4" })
158
122
  expect(actual).to eq(%w[foo bar baz number4])
159
123
  end
160
124
  end
161
125
 
162
- context "with more than the allowed number of args" do
163
- it "runs" do
164
- invoke!("foo", "bar", "baz", "number4", "extra")
165
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
166
- end
167
- end
168
-
169
126
  context "with extra named args" do
170
127
  it "ignores extra args" do
171
- invoke!(a: "foo", b: "bar", c: "baz", extra3: 3)
128
+ invoke!(args: { "a" => "foo", "b" => "bar", "c" => "baz", "extra3" => 3 })
172
129
  expect(actual).to eq(["foo", "bar", "baz", 2.781])
173
130
  end
174
131
  end
@@ -192,28 +149,21 @@ describe "Simple::Service.invoke" do
192
149
 
193
150
  context "with the required number of args" do
194
151
  it "runs" do
195
- invoke!("foo")
152
+ invoke!(args: { "a" => "foo" })
196
153
  expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
197
154
  end
198
155
  end
199
156
 
200
157
  context "with the allowed number of args" do
201
158
  it "runs" do
202
- invoke!("foo", "bar", "baz", e: "number4")
159
+ invoke!(args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4" })
203
160
  expect(actual).to eq(%w[foo bar baz number4])
204
161
  end
205
162
  end
206
163
 
207
- context "with more than the allowed number of args" do
208
- it "runs" do
209
- invoke!("foo", "bar", "baz", "extra", e: "number4")
210
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
211
- end
212
- end
213
-
214
164
  context "with extra named args" do
215
165
  it "ignores extra args" do
216
- invoke!("foo", "bar", "baz", e: "number4", extra3: 3)
166
+ invoke!(args: { "a" => "foo", "b" => "bar", "c" => "baz", "e" => "number4", "extra3" => 3 })
217
167
  expect(actual).to eq(["foo", "bar", "baz", "number4"])
218
168
  end
219
169
  end
@@ -237,30 +187,42 @@ describe "Simple::Service.invoke" do
237
187
 
238
188
  context "with the required number of args" do
239
189
  it "runs" do
240
- invoke!("foo")
190
+ invoke!(args: { "a" => "foo" })
241
191
  expect(actual).to eq(["foo", "queen bee", [], 2.781])
242
192
  end
243
193
  end
244
194
 
245
195
  context "with the allowed number of args" do
246
196
  it "runs" do
247
- invoke!("foo", "bar", "baz", e: "number4")
197
+ invoke!(args: { "a" => "foo", "b" => "bar", "args" => ["baz"] }, flags: { "e" => "number4" })
248
198
  expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
249
199
  end
250
200
  end
251
201
 
252
- context "with more than the allowed number of args" do
253
- it "runs" do
254
- invoke!("foo", "bar", "baz", "extra", e: "number4")
202
+ context "with variadic args" do
203
+ it "sends the variadic args from the args: parameter" do
204
+ invoke!(args: { "a" => "foo", "b" => "bar", "args" => ["baz", "extra"] }, flags: { "e" => "number4", "extra3" => 2 })
255
205
  expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
256
206
  end
257
- end
258
207
 
259
- context "with extra named args" do
260
- it "ignores extra args" do
261
- invoke!("foo", "bar", "baz", e: "number4", extra3: 3)
262
- expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
208
+ it "sends the variadic args from the flags: parameter" do
209
+ invoke!(args: { "a" => "foo", "b" => "bar" }, flags: { "args" => ["baz", "extra"], "e" => "number4", "extra3" => 2 })
210
+ expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
263
211
  end
264
212
  end
265
213
  end
214
+
215
+ describe "calling with symbolized Hashes" do
216
+ it "raises ArgumentError" do
217
+ hsh = { a: "foo", "b" => "KJH" }
218
+
219
+ expect do
220
+ invoke!(args: hsh)
221
+ end.to raise_error(Expectation::Matcher::Mismatch)
222
+
223
+ expect do
224
+ invoke!(flags: hsh)
225
+ end.to raise_error(Expectation::Matcher::Mismatch)
226
+ end
227
+ end
266
228
  end