From 9f0e80591ab1f3c4967575574fed37754ef2403b Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 26 Sep 2012 13:21:38 -0400 Subject: [PATCH] Fix Repository role spec --- app/roles/repository.rb | 3 +++ spec/roles/repository_spec.rb | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/roles/repository.rb b/app/roles/repository.rb index 7118f156..191a6d70 100644 --- a/app/roles/repository.rb +++ b/app/roles/repository.rb @@ -45,14 +45,17 @@ module Repository File.exists?(hook_file) end + # Returns an Array of branch names def branches repo.branches.collect(&:name).sort end + # Returns an Array of tag names def tags repo.tags.collect(&:name).sort.reverse end + # Returns an Array of branch and tag names def ref_names [branches + tags].flatten end diff --git a/spec/roles/repository_spec.rb b/spec/roles/repository_spec.rb index 0fda57a3..c4e0e9de 100644 --- a/spec/roles/repository_spec.rb +++ b/spec/roles/repository_spec.rb @@ -21,27 +21,27 @@ describe Project, "Repository" do end describe "#discover_default_branch" do - let(:master) { double(name: 'master') } - let(:stable) { double(name: 'stable') } + let(:master) { 'master' } + let(:stable) { 'stable' } it "returns 'master' when master exists" do - project.should_receive(:heads).and_return([stable, master]) + project.should_receive(:branches).at_least(:once).and_return([stable, master]) project.discover_default_branch.should == 'master' end it "returns non-master when master exists but default branch is set to something else" do project.default_branch = 'stable' - project.should_receive(:heads).and_return([stable, master]) + project.should_receive(:branches).at_least(:once).and_return([stable, master]) project.discover_default_branch.should == 'stable' end it "returns a non-master branch when only one exists" do - project.should_receive(:heads).and_return([stable]) + project.should_receive(:branches).at_least(:once).and_return([stable]) project.discover_default_branch.should == 'stable' end it "returns nil when no branch exists" do - project.should_receive(:heads).and_return([]) + project.should_receive(:branches).at_least(:once).and_return([]) project.discover_default_branch.should be_nil end end