Skip to content

Instantly share code, notes, and snippets.

@rimian
Last active March 16, 2022 02:19
Show Gist options
  • Save rimian/3c9ee8360958d45a5434371cd2091245 to your computer and use it in GitHub Desktop.
Save rimian/3c9ee8360958d45a5434371cd2091245 to your computer and use it in GitHub Desktop.
best way to test a factory method
class Pipeline
def self.run
new.run
end
def run
# do stuff
end
end
RSpec.describe Pipeline do
subject { described_class }
# rubocop fails this
it 'runs a new instance' do
expect(subject).to receive_message_chain(:new, :run)
subject.run
end
# and fails this
it 'runs a new instance' do
expect_any_instance_of(subject).to receive(:run)
subject.run
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment