Test repository integration

How to test repository integration ?

I want to do similar to this : https://relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/expect-change

But here because we don’t deal with active record, how to do

it “should increment the count” do
expect{Counter.increment}.to change{Counter.count}.from(0).to(1)
end

Just do:

expect { your_repo.some_method }
  .to change { affected_relation.count }.from(0).to(1)

In general, it’s good to expose relations in your specs. I typically have something like:

let(:relations) { rom.relations }

…in shared examples included in specs that need db setup.

1 Like