forked from schacon/ticgit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added rspec tests that at least give it a baseline of coverage
also had to tweak the patch submitted for finding the .git directory from looking for GIT_DIR to looking for GIT_WORKING_DIR
- Loading branch information
Showing
6 changed files
with
291 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
require File.dirname(__FILE__) + "/spec_helper" | ||
|
||
describe TicGit::Base do | ||
include TicGitSpecHelper | ||
|
||
before(:all) do | ||
@path = setup_new_git_repo | ||
@orig_test_opts = test_opts | ||
@ticgit = TicGit.open(@path, @orig_test_opts) | ||
end | ||
|
||
it "should have 4 ticket states" do | ||
@ticgit.tic_states.size.should eql(4) | ||
end | ||
|
||
it "should be able to create new tickets" do | ||
@ticgit.tickets.size.should eql(0) | ||
@ticgit.ticket_new('my new ticket').should be_an_instance_of(TicGit::Ticket) | ||
@ticgit.tickets.size.should eql(1) | ||
end | ||
|
||
it "should be able to list existing tickets" do | ||
@ticgit.ticket_new('my second ticket').should be_an_instance_of(TicGit::Ticket) | ||
list = @ticgit.ticket_list | ||
list.first.should be_an_instance_of(TicGit::Ticket) | ||
list.size.should eql(2) | ||
end | ||
|
||
it "should be able to change the state of a ticket" do | ||
tic = @ticgit.ticket_list.first | ||
@ticgit.ticket_change('resolved', tic.ticket_id) | ||
tic = @ticgit.ticket_show(tic.ticket_id) | ||
tic.state.should eql('resolved') | ||
end | ||
|
||
it "should not be able to change the state of a ticket to something invalid" do | ||
tic = @ticgit.ticket_list.first | ||
@ticgit.ticket_change('resolve', tic.ticket_id) | ||
tic = @ticgit.ticket_show(tic.ticket_id) | ||
tic.state.should_not eql('resolve') | ||
end | ||
|
||
it "should only show open tickets by default" do | ||
@ticgit.ticket_new('my third ticket') | ||
tics = @ticgit.ticket_list | ||
states = tics.map { |t| t.state }.uniq | ||
states.size.should eql(1) | ||
states.first.should eql('open') | ||
end | ||
|
||
it "should be able to filter tickets on state" do | ||
tics = @ticgit.ticket_list(:state => 'resolved') | ||
tics.size.should eql(1) | ||
tics = @ticgit.ticket_list(:state => 'open') | ||
tics.size.should eql(2) | ||
end | ||
|
||
it "should be able to save and recall filtered ticket lists" do | ||
tics = @ticgit.ticket_list(:state => 'resolved', :save => 'resolve') | ||
tics.size.should eql(1) | ||
rtics = @ticgit.ticket_list(:saved => 'resolve') | ||
tics.size.should eql(1) | ||
end | ||
|
||
it "should be able to comment on tickets" do | ||
t = @ticgit.ticket_new('my fourth ticket') | ||
t.comments.size.should eql(0) | ||
|
||
@ticgit.ticket_comment('my new comment', t.ticket_id) | ||
t = @ticgit.ticket_show(t.ticket_id) | ||
t.comments.size.should eql(1) | ||
t.comments.first.comment.should eql('my new comment') | ||
end | ||
|
||
it "should retrieve specific tickets" do | ||
tid = @ticgit.ticket_list.last.ticket_id | ||
tic = @ticgit.ticket_show(tid) | ||
tic.ticket_id.should eql(tid) | ||
end | ||
|
||
it "should be able to checkout a ticket" do | ||
tid = @ticgit.ticket_list.last.ticket_id | ||
@ticgit.ticket_checkout(tid) | ||
@ticgit.ticket_show.ticket_id.should eql(tid) | ||
end | ||
|
||
it "should resolve partial shas into ticket" do | ||
tid = @ticgit.ticket_list.last.ticket_id | ||
@ticgit.ticket_checkout(tid[0, 5]) | ||
@ticgit.ticket_show.ticket_id.should eql(tid) | ||
|
||
@ticgit.ticket_checkout(tid[0, 20]) | ||
@ticgit.ticket_show.ticket_id.should eql(tid) | ||
end | ||
|
||
it "should resolve order number from most recent list into ticket" do | ||
tics = @ticgit.ticket_list(:state => 'open') | ||
@ticgit.ticket_show('1').ticket_id.should eql(tics[0].ticket_id) | ||
@ticgit.ticket_show('2').ticket_id.should eql(tics[1].ticket_id) | ||
end | ||
|
||
it "should be able to tag a ticket" do | ||
t = @ticgit.ticket_list.last | ||
t.tags.size.should eql(0) | ||
@ticgit.ticket_tag('newtag', t.ticket_id) | ||
t = @ticgit.ticket_show(t.ticket_id) | ||
t.tags.size.should eql(1) | ||
t.tags.first.should eql('newtag') | ||
end | ||
|
||
it "should not be able to tag a ticket with a blank tag" do | ||
t = @ticgit.ticket_new('my fourth ticket', :tags => [' ']) | ||
t.tags.size.should eql(0) | ||
|
||
@ticgit.ticket_tag(' ', t.ticket_id) | ||
t = @ticgit.ticket_show(t.ticket_id) | ||
t.tags.size.should eql(0) | ||
|
||
@ticgit.ticket_tag('', t.ticket_id) | ||
t = @ticgit.ticket_show(t.ticket_id) | ||
t.tags.size.should eql(0) | ||
|
||
@ticgit.ticket_tag(',mytag', t.ticket_id) | ||
t = @ticgit.ticket_show(t.ticket_id) | ||
t.tags.size.should eql(1) | ||
t.tags.first.should eql('mytag') | ||
end | ||
|
||
it "should be able to remove a tag from a ticket" do | ||
t = @ticgit.ticket_new('my next ticket', :tags => ['scotty', 'chacony']) | ||
t.tags.size.should eql(2) | ||
|
||
@ticgit.ticket_tag('scotty', t.ticket_id, :remove => true) | ||
t.tags.size.should eql(2) | ||
t.tags.first.should eql('chacony') | ||
end | ||
|
||
it "should save state to disk after a new ticket" do | ||
time = File.stat(@ticgit.state).size | ||
t = @ticgit.ticket_new('my next ticket', :tags => ['scotty', 'chacony']) | ||
File.stat(@ticgit.state).size.should_not eql(time) | ||
end | ||
|
||
end | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require File.dirname(__FILE__) + "/spec_helper" | ||
|
||
describe TicGit::CLI do | ||
include TicGitSpecHelper | ||
|
||
before(:all) do | ||
@path = setup_new_git_repo | ||
@orig_test_opts = test_opts | ||
@ticgit = TicGit.open(@path, @orig_test_opts) | ||
end | ||
|
||
it "should list the tickets" | ||
|
||
it "should show a ticket" | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/../lib/ticgit") | ||
require 'fileutils' | ||
require 'logger' | ||
|
||
module TicGitSpecHelper | ||
|
||
def setup_new_git_repo | ||
temp = Tempfile.new('ticgit') | ||
p = temp.path | ||
temp.unlink | ||
Dir.mkdir(p) | ||
Dir.chdir(p) do | ||
g = Git.init | ||
new_file('test', 'content') | ||
Dir.mkdir('subdir') | ||
new_file('subdir/testfile', 'content2') | ||
g.add | ||
g.commit('first commit') | ||
end | ||
p | ||
end | ||
|
||
def setup_existing_ticgit_repo | ||
end | ||
|
||
def test_opts | ||
temp = Tempfile.new('ticdir') | ||
p = temp.path | ||
temp.unlink | ||
Dir.mkdir(p) | ||
logger = Logger.new(Tempfile.new('ticgit-log')) | ||
{ :tic_dir => p, :logger => logger } | ||
end | ||
|
||
|
||
def new_file(name, contents) | ||
File.open(name, 'w') do |f| | ||
f.puts contents | ||
end | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
## | ||
# rSpec Hash additions. | ||
# | ||
# From | ||
# * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F | ||
# * Neil Rahilly | ||
|
||
class Hash | ||
|
||
## | ||
# Filter keys out of a Hash. | ||
# | ||
# { :a => 1, :b => 2, :c => 3 }.except(:a) | ||
# => { :b => 2, :c => 3 } | ||
|
||
def except(*keys) | ||
self.reject { |k,v| keys.include?(k || k.to_sym) } | ||
end | ||
|
||
## | ||
# Override some keys. | ||
# | ||
# { :a => 1, :b => 2, :c => 3 }.with(:a => 4) | ||
# => { :a => 4, :b => 2, :c => 3 } | ||
|
||
def with(overrides = {}) | ||
self.merge overrides | ||
end | ||
|
||
## | ||
# Returns a Hash with only the pairs identified by +keys+. | ||
# | ||
# { :a => 1, :b => 2, :c => 3 }.only(:a) | ||
# => { :a => 1 } | ||
|
||
def only(*keys) | ||
self.reject { |k,v| !keys.include?(k || k.to_sym) } | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require File.dirname(__FILE__) + "/spec_helper" | ||
|
||
describe TicGit do | ||
include TicGitSpecHelper | ||
|
||
before(:all) do | ||
@path = setup_new_git_repo | ||
@orig_test_opts = test_opts | ||
@ticgit = TicGit.open(@path, @orig_test_opts) | ||
end | ||
|
||
it "should create a new branch if it's not there" do | ||
br = @ticgit.git.branches.map { |b| b.name } | ||
br.should include('ticgit') | ||
end | ||
|
||
it "should find an existing ticgit branch if it's there" do | ||
tg = TicGit.open(@path, test_opts) | ||
@ticgit.git.branches.size.should eql(tg.git.branches.size) | ||
end | ||
|
||
it "should find the .git directory if it's there" do | ||
@ticgit.git.dir.path.should eql(@path) | ||
end | ||
|
||
it "should look for the .git directory until it finds it" do | ||
tg = TicGit.open(File.join(@path, 'subdir'), @orig_test_opts) | ||
tg.git.dir.path.should eql(@path) | ||
end | ||
|
||
it "should add a .hold file to a new branch" | ||
|
||
end |