interactor-contracts icon indicating copy to clipboard operation
interactor-contracts copied to clipboard

Support for shoulda-matcher style rspec matcher for testing interactors with contracts

Open prpetten opened this issue 1 year ago • 1 comments

Rather than add a bunch of boilerplate tests for contract breaches, I was wondering if there was something similar to the shoulda-matchers. https://github.com/thoughtbot/shoulda-matchers/tree/main

So for

class MyInteractor
  include Interactor
  include Interactor::Contracts

  expects do
    required(:argument1).filled
    required(:argument2).filled
  end
  
  def call
    #does stuff
  end
end

We could have a spec

describe MyInteractor do
  describe 'validations' do
    it { should validate_presence_of(:argument1) }
    it { should validate_presence_of(:argument2) }
  end
end

prpetten avatar Feb 09 '24 21:02 prpetten

I'm open to the idea! Happy to accept a PR.

michaelherold avatar Feb 09 '24 22:02 michaelherold