diff --git a/lib/interaktor/callable.rb b/lib/interaktor/callable.rb index 7883d77..fe6ebe6 100644 --- a/lib/interaktor/callable.rb +++ b/lib/interaktor/callable.rb @@ -144,6 +144,10 @@ def success(*attributes, **options) # # @return [Interaktor::Context] the context, following interaktor execution def call(context = {}) + unless context.is_a?(Hash) || context.is_a?(Interaktor::Context) + raise ArgumentError, "Expected a hash argument when calling the interaktor, got a #{context.class} instead." + end + apply_default_optional_attributes(context) verify_attribute_presence(context) @@ -161,6 +165,10 @@ def call(context = {}) # # @return [Interaktor::Context] the context, following interaktor execution def call!(context = {}) + unless context.is_a?(Hash) || context.is_a?(Interaktor::Context) + raise ArgumentError, "Expected a hash argument when calling the interaktor, got a #{context.class} instead." + end + apply_default_optional_attributes(context) verify_attribute_presence(context) diff --git a/spec/support/lint.rb b/spec/support/lint.rb index 28a8c08..a45b376 100644 --- a/spec/support/lint.rb +++ b/spec/support/lint.rb @@ -17,6 +17,12 @@ interaktor.call(baz: "wadus") }.to raise_error(an_instance_of(Interaktor::Error::UnknownAttributeError).and having_attributes(attributes: [:baz])) end + + it "fails when a non-hash or non-context argument is passed" do + expect { + interaktor.call("foo") + }.to raise_error(ArgumentError, /Expected a hash argument/) + end end describe ".call!" do @@ -35,6 +41,12 @@ interaktor.call!(baz: "wadus") }.to raise_error(an_instance_of(Interaktor::Error::UnknownAttributeError).and having_attributes(attributes: [:baz])) end + + it "fails when a non-hash or non-context argument is passed" do + expect { + interaktor.call!("foo") + }.to raise_error(ArgumentError, /Expected a hash argument/) + end end describe "#run" do