How to write rspec tests for ruby Script that works with Git -
i have ruby script checks changes between git repo , files @ url endpoints. if changes exist, commits them , pushes them repo. i'd write rspec tests script, i'm having trouble understanding how so, since don't want tests push actual git repo. i'm thinking need set sort of mock repository i'm not entirely sure. suggestions how best write unit tests such script appreciated.
i think can make use of fact it's legal push local "bare" repository, i.e. need following steps:
- create "bare" repository
repo1
(i.e. repository, doesn't have working copy, consists entirely of contents of.git
folder) - clone regular repository
repo2
repo1
. - make changes in
repo2
(add, commit, push). check push successful. - check data available in
repo1
too.
here's sample console session in /tmp
directory:
ruby-2.2.0 in /tmp ♥ mkdir repo1 ruby-2.2.0 in /tmp ♥ cd repo1 ruby-2.2.0 in /tmp/repo1 ♥ git init --bare initialized empty git repository in /private/tmp/repo1/ ruby-2.2.0 in /tmp/repo1 ♥ cd .. ruby-2.2.0 in /tmp ♥ git clone repo1 repo2 cloning 'repo2'... warning: appear have cloned empty repository. done. ruby-2.2.0 in /tmp ♥ cd repo2 ruby-2.2.0 in /tmp/repo2 on master ♥ git remote -v origin /tmp/repo1 (fetch) origin /tmp/repo1 (push) ruby-2.2.0 in /tmp/repo2 on master ♥ cd .. ruby-2.2.0 in /tmp ♥ cd - /tmp/repo2 ruby-2.2.0 in /tmp/repo2 on master ♥ echo 'ohai!' >> readme.txt ruby-2.2.0 in /tmp/repo2 on master ♥ git add readme.txt ruby-2.2.0 in /tmp/repo2 on master ♥ git commit [master (root-commit) 1f1fb96] first commit 1 file changed, 1 insertion(+) create mode 100644 readme.txt ruby-2.2.0 in /tmp/repo2 on master ♥ git push counting objects: 3, done. writing objects: 100% (3/3), 227 bytes | 0 bytes/s, done. total 3 (delta 0), reused 0 (delta 0) /tmp/repo1 * [new branch] master -> master ruby-2.2.0 in /tmp/repo2 on master ♥ git log commit 1f1fb96deaaf15fa33f1682d87d85014b59b36db author: alexey shein <alexey.shein.dev@gmail.com> date: tue sep 22 01:22:12 2015 +0500 first commit ruby-2.2.0 in /tmp/repo2 on master ♥ cd .. ruby-2.2.0 in /tmp ♥ cd repo1 ruby-2.2.0 in /tmp/repo1 ♥ ls head config description hooks info objects refs ruby-2.2.0 in /tmp/repo1 ♥ git log commit 1f1fb96deaaf15fa33f1682d87d85014b59b36db author: alexey shein <alexey.shein.dev@gmail.com> date: tue sep 22 01:22:12 2015 +0500 first commit ruby-2.2.0 in /tmp/repo1 ♥
Comments
Post a Comment