Created
July 12, 2017 07:12
-
-
Save zaru/2c102235b952541c57854778e8cc6beb to your computer and use it in GitHub Desktop.
他のクラスに依存しているクラスのテスト・モックスタブ
This file contains hidden or 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 A | |
| def perform | |
| b = B.new | |
| b.execute | |
| end | |
| end | |
| class B | |
| def execute | |
| "本物" | |
| end | |
| end | |
| it "" do | |
| mock = B.new | |
| allow(B).to receive(:new).and_return(mock) | |
| allow(mock).to receive(:execute).and_return("stub method") | |
| A.new.perform | |
| expect(mock).to have_received(:execute).once | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
なるほど、それなら仕方ないですね。
はい、
allow_any_instance_ofはできるだけ使わない方がいいですね。(といいつつ、僕は今もたまに使いますがw)