For default Rails, you can add so called ActiveModel::Lint::Tests
to see if your models adhere to parts of the ActiveModel.
I would like to call these, or an equivalent thereof in my Rspec tests.
- I don't want to test the exact behaviour: the lint tests only spec that a certain interface exists. I want to only spec that the interface exists.
- I rather not test too close implementation. Merely testing that a module is included is not really the same as testing an interface exists.
Is there a trick to run and include the Rails core ActiveModel::Lint::Tests
in rspec examples? Are there alternatives, specially built for Rspec that run such lint-tests?
Some background:
I am building models that don't inherit from Activerecord::Base
, but instead act as factories or state-machines. In Rails also known as Service-Objects. These should feel like ActiveModels for the user. Things like
@services << CompositeService.new(name: 'foo', children: [{ name: 'bar' }])
render @services
should be possible. Such a CompositeService
should then, have activemodel naming, partial paths, caching-ids and so on.