I’m defining a boundary between the delivery mechanism (web) and the business logic. I want to test the delivery mechanism in isolation, and to achieve that I’m stubbing the business logic.
Given the following code on an endpoint:
post '/people' do Operations::People::CreatePerson.new.call(declared(params)) do |m| m.success do |person| status 201 person end m.failure do |errors| status 422 errors end end end
The following operation:
module Operations module People class CreatePerson include Dry::Matcher.for(:call, with: ComplexMatcher) include Operations::Result::Mixin def call(person_attributes) person = Person.create!(person_attributes) Success(value: person) rescue ActiveRecord::ActiveRecordError => error Failure(value: error.message, code: :not_created) end end end end
And the following stub in an endpoint test:
I get this error:
Using any_instance to stub a method (call) that has been defined on a prepended module (#<Module:0x007ff2d3bda8d0>) is not supported.
This happens because
Dry::Matcher.for prepends a module when included.
Is there a way to overcome this problem?