Last active
March 16, 2022 02:19
-
-
Save rimian/3c9ee8360958d45a5434371cd2091245 to your computer and use it in GitHub Desktop.
best way to test a factory method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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