|
RSpec.describe User do
describe ".some_method" do
it "calls #foo on each user returned by the `some_scope` scope" do
users = [ instance_spy(User), instance_spy(User) ]
allow(User).to receive(:some_scope).and_return(users)
User.some_method
expect(users).to all have_received(:foo)
end
end
end
This isn’t necessarily the best way to test this code. In a real system, I might favor an integration test for this code depending on what the logic of some_scope and foo are, whether or not they are tested elsewhere, etc — but for an isolated unit test it’s about the best you can do.
HTH,
Myron
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/8f5ab842-e555-494d-8dbe-9c62cf094360%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.