spec/simple/service/action_invoke3_spec.rb in simple-service-0.2.2 vs spec/simple/service/action_invoke3_spec.rb in simple-service-0.2.3
- old
+ new
@@ -4,20 +4,10 @@
describe "Simple::Service.invoke3" do
let(:service) { InvokeTestService }
let(:action) { nil }
- # a shortcut
- def invoke3!(*args, **keywords)
- @actual = ::Simple::Service.invoke3(service, action, *args, **keywords)
- # rescue ::StandardError => e
- rescue ::Simple::Service::ArgumentError => e
- @actual = e
- end
-
- attr_reader :actual
-
# when calling #invoke3 using positional arguments they will be matched against
# positional arguments of the invoke3d method - but they will not be matched
# against named arguments.
#
# When there are not enough positional arguments to match the number of required
@@ -35,37 +25,38 @@
let(:action) { :no_params }
context "calling without args" do
it "runs the action" do
- invoke3!
+ actual = ::Simple::Service.invoke3(service, action)
expect(actual).to eq("service2 return")
end
end
context "calling with extra positional args" do
it "raises ExtraArguments" do
- invoke3!("foo", "bar")
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
- expect(actual.to_s).to match(/"foo", "bar"/)
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar")
+ }.to raise_error(::Simple::Service::ExtraArgumentError, /"foo", "bar"/)
end
end
context "calling with extra named args" do
- it "ignores extra args" do
- invoke3!(foo: "foo", bar: "bar")
- expect(actual).to eq("service2 return")
+ it "raises an ExtraArguments error" do
+ expect {
+ ::Simple::Service.invoke3(service, action, foo: "foo", bar: "bar")
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
context "calling with an additional hash arg" do
- xit "ignores extra args" do
- args = []
- args.push foo: "foo", bar: "bar"
- invoke3!(*args)
-
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
+ it "ignores extra args" do
+ expect {
+ args = []
+ args.push foo: "foo", bar: "bar"
+ ::Simple::Service.invoke3(service, action, *args)
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
end
context "calling an action w/positional parameters" do
@@ -77,48 +68,52 @@
let(:action) { :positional_params }
context "without args" do
it "raises MissingArguments" do
- invoke3!
- expect(actual).to be_a(::Simple::Service::MissingArguments)
+ expect {
+ ::Simple::Service.invoke3(service, action)
+ }.to raise_error(::Simple::Service::MissingArgumentError)
end
end
context "with the required number of args" do
it "runs" do
- invoke3!("foo", "bar")
+ actual = ::Simple::Service.invoke3(service, action, "foo", "bar")
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
end
end
context "with the allowed number of args" do
it "runs" do
- invoke3!("foo", "bar", "baz", "number4")
+ actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "number4")
expect(actual).to eq(%w[foo bar baz number4])
end
end
context "with more than the allowed number of args" do
it "raises ExtraArguments" do
- invoke3!("foo", "bar", "baz", "number4", "extra")
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "number4", "extra")
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
context "calling with extra named args" do
it "ignores extra args" do
- invoke3!("foo", "bar", "baz", extra3: 3)
- expect(actual).to eq(["foo", "bar", "baz", 2.781])
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", extra3: 3)
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
context "calling with an additional hash arg" do
- xit "raises ExtraArguments" do
- args = ["foo", "bar", "baz", extra3: 3]
- invoke3!(*args)
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
+ it "raises ExtraArguments" do
+ expect {
+ args = ["foo", "bar", "baz", extra3: 3]
+ ::Simple::Service.invoke3(service, action, *args)
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
end
context "calling an action w/named parameters" do
@@ -130,40 +125,43 @@
let(:action) { :named_params }
context "without args" do
it "raises MissingArguments" do
- invoke3!
- expect(actual).to be_a(::Simple::Service::MissingArguments)
+ expect {
+ ::Simple::Service.invoke3(service, action)
+ }.to raise_error(::Simple::Service::MissingArgumentError)
end
end
context "with the required number of args" do
it "runs" do
- invoke3!(a: "foo", b: "bar")
+ actual = ::Simple::Service.invoke3(service, action, a: "foo", b: "bar")
expect(actual).to eq(["foo", "bar", "speed-of-light", 2.781])
end
end
context "with the allowed number of args" do
it "runs" do
- invoke3!(a: "foo", b: "bar", c: "baz", e: "number4")
+ actual = ::Simple::Service.invoke3(service, action, a: "foo", b: "bar", c: "baz", e: "number4")
expect(actual).to eq(%w[foo bar baz number4])
end
end
context "with more than the allowed number of args" do
it "runs" do
- invoke3!("foo", "bar", "baz", "number4", "extra")
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "number4", "extra")
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
context "with extra named args" do
it "ignores extra args" do
- invoke3!(a: "foo", b: "bar", c: "baz", extra3: 3)
- expect(actual).to eq(["foo", "bar", "baz", 2.781])
+ expect {
+ ::Simple::Service.invoke3(service, action, a: "foo", b: "bar", c: "baz", extra3: 3)
+ }.to raise_error(::Simple::Service::ArgumentError)
end
end
end
context "calling an action w/mixed and optional parameters" do
@@ -175,40 +173,43 @@
let(:action) { :mixed_optional_params }
context "without args" do
it "raises MissingArguments" do
- invoke3!
- expect(actual).to be_a(::Simple::Service::MissingArguments)
+ expect {
+ ::Simple::Service.invoke3(service, action)
+ }.to raise_error(::Simple::Service::MissingArgumentError)
end
end
context "with the required number of args" do
it "runs" do
- invoke3!("foo")
+ actual = ::Simple::Service.invoke3(service, action, "foo")
expect(actual).to eq(["foo", "default-b", "speed-of-light", 2.781])
end
end
context "with the allowed number of args" do
it "runs" do
- invoke3!("foo", "bar", "baz", e: "number4")
+ actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4")
expect(actual).to eq(%w[foo bar baz number4])
end
end
context "with more than the allowed number of args" do
- it "runs" do
- invoke3!("foo", "bar", "baz", "extra", e: "number4")
- expect(actual).to be_a(::Simple::Service::ExtraArguments)
+ it "raises an ExtraArguments error" do
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "extra", e: "number4")
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
context "with extra named args" do
- it "ignores extra args" do
- invoke3!("foo", "bar", "baz", e: "number4", extra3: 3)
- expect(actual).to eq(["foo", "bar", "baz", "number4"])
+ it "raises an ExtraArguments error" do
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4", extra3: 3)
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
end
context "calling an action w/mixed and variadic parameters" do
@@ -220,39 +221,41 @@
let(:action) { :variadic_params }
context "without args" do
it "raises MissingArguments" do
- invoke3!
- expect(actual).to be_a(::Simple::Service::MissingArguments)
+ expect {
+ ::Simple::Service.invoke3(service, action)
+ }.to raise_error(::Simple::Service::MissingArgumentError)
end
end
context "with the required number of args" do
it "runs" do
- invoke3!("foo")
+ actual = ::Simple::Service.invoke3(service, action, "foo")
expect(actual).to eq(["foo", "queen bee", [], 2.781])
end
end
context "with the allowed number of args" do
it "runs" do
- invoke3!("foo", "bar", "baz", e: "number4")
+ actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4")
expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
end
end
context "with more than the allowed number of args" do
it "runs" do
- invoke3!("foo", "bar", "baz", "extra", e: "number4")
+ actual = ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", "extra", e: "number4")
expect(actual).to eq(["foo", "bar", ["baz", "extra"], "number4"])
end
end
context "with extra named args" do
- it "ignores extra args" do
- invoke3!("foo", "bar", "baz", e: "number4", extra3: 3)
- expect(actual).to eq(["foo", "bar", ["baz"], "number4"])
+ it "raises an ExtraArguments error" do
+ expect {
+ ::Simple::Service.invoke3(service, action, "foo", "bar", "baz", e: "number4", extra3: 3)
+ }.to raise_error(::Simple::Service::ExtraArgumentError)
end
end
end
end