-
-
Save jbrains/726460 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
public class CreateActionTest { | |
def mockery = new JUnit4Mockery(); | |
def modelRepository = mockery.mock(ModelRepository.class); // corresponds to class methods on Model in Rails | |
def model = new Model(); // treated as Entity (DDD sense) | |
def controller = new Controller(modelRepository); | |
@Before | |
public void supposeModelRepositoryCreatesOurModelObject() { | |
mockery.stub(modelRepository).create().will(returnValue(model)); | |
} | |
@Test | |
public void savesModelByExpectingThenActing() throws Exception { | |
mockery.oneOf(modelRepository).save(with(same(model))); | |
controller.create(); | |
} | |
@Test | |
public void savesModelByActingThenVerifying() throws Exception { | |
controller.create(); | |
mockery.verify(modelRepository).save(with(same(model))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment