|
| 1 | +require File.expand_path('../../spec_helper', __FILE__) |
| 2 | +require 'git' |
| 3 | + |
| 4 | +describe Git do |
| 5 | + SAMPLE_REV = '51b986619d88f7ba98be7d271188785cbbb541a0'.freeze |
| 6 | + |
| 7 | + describe :from_shell do |
| 8 | + it "should be backtick" do |
| 9 | + Git.from_shell('pwd').should == `pwd` |
| 10 | + end |
| 11 | + end |
| 12 | + |
| 13 | + describe :show do |
| 14 | + it "should get data from shell: git show" do |
| 15 | + expected = 'some data from git show' |
| 16 | + mock(Git).from_shell("git show #{SAMPLE_REV} -w") { expected } |
| 17 | + Git.show(SAMPLE_REV).should == expected |
| 18 | + end |
| 19 | + |
| 20 | + it "should strip given revision" do |
| 21 | + mock(Git).from_shell("git show #{SAMPLE_REV} -w") |
| 22 | + Git.show("#{SAMPLE_REV}\n") |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + describe :branch_heads do |
| 27 | + before(:each) do |
| 28 | + mock(Git).from_shell("git rev-parse --branches") { "some\npopular\ntext\n" } |
| 29 | + end |
| 30 | + |
| 31 | + it "should get branch heads from shell" do |
| 32 | + lambda { Git.branch_heads }.should_not raise_error |
| 33 | + end |
| 34 | + |
| 35 | + it "should return array of lines" do |
| 36 | + Git.branch_heads.should == %w[ some popular text ] |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + |
| 41 | + describe :repo_name do |
| 42 | + # this spec written because I replaced `pwd` with Dir.pwd |
| 43 | + it "Dir.pwd should be same as `pwd`.chomp" do |
| 44 | + Dir.pwd.should == `pwd`.chomp |
| 45 | + end |
| 46 | + |
| 47 | + it "should return hooks.emailprefix if it's not empty" do |
| 48 | + expected = "name of repo" |
| 49 | + mock(Git).from_shell("git config hooks.emailprefix") { expected } |
| 50 | + dont_allow(Dir).pwd |
| 51 | + Git.repo_name.should == expected |
| 52 | + end |
| 53 | + |
| 54 | + it "should return folder name if no emailprefix and directory not ended with .git" do |
| 55 | + mock(Git).from_shell("git config hooks.emailprefix") { " " } |
| 56 | + mock(Dir).pwd { "/home/someuser/repositories/myrepo" } |
| 57 | + Git.repo_name.should == "myrepo" |
| 58 | + end |
| 59 | + |
| 60 | + it "should return folder name without extension if no emailprefix and directory ended with .git" do |
| 61 | + mock(Git).from_shell("git config hooks.emailprefix") { " " } |
| 62 | + mock(Dir).pwd { "/home/someuser/repositories/myrepo.git" } |
| 63 | + Git.repo_name.should == "myrepo" |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | +end |
| 68 | + |
| 69 | +__END__ |
| 70 | + |
| 71 | + vim: tabstop=2 expandtab shiftwidth=2 |
0 commit comments