Cucumber stories with external dependencies
The app I'm creating uses git to move repositories around. I'm trying to find a strategy that will let me implement a step like:
Then the commit "d786239开发者_StackOverflow社区d8sd" is pushed from "git@github.com:opsb/conference_hub" to "git@heroku.com:conference_hub_ci.git"
Given the command uses git, which interacts with the filesystem, how do I implement this step in a way that will be rolled back afterwards?
I would not be using hard coded paths to the git repos. That way, they can vary by environment. As a given in scenario, you can say:
Given "a repo exists at "user@domain.com:/some/path.git"
The step would, of course create a git repo in a known state in that location.
When "something or other"
Then the commit "d786239d8sd" is pushed from "user@domain.com:/some/path" to "anotheruser@anotherplace.com:/some/path.git"
This strategy allows you to still do full-stack testing without trying to test that Github, Heroku, and git all work.
Background:
Given a source repository exists at "user@domain.com:/first/path.git"
And a destination repository exists at "user@domain.com:/second/path.git"
Scenario:
Given I have a commit, referenced with 'd786239d8sd', in the source repo
When I execute my application in a way I only know how
Then I expect the commit is pushed from the source repo to the destination repo
I would steer clear in most cases from testing git and your file system (if you can help it for most of your tests) as it seems likely that will have long setup and teardown times. If you are integrating with git, I would test to enforce that your code adheres to the contract outlined by git. The end result of this may be simply setting up expectations that methods were called or a command-line operation was successfully created that matches your expectations to perform that operation.
This answers your question in that traditional 'Internet' way, by saying: just don't do that so that you don't have to do undo that.
精彩评论