Skip to content

Commit

Permalink
merge #with_latest_code with #with_revision [integrity#5 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Jul 20, 2008
1 parent fbea5eb commit 31813ae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
8 changes: 2 additions & 6 deletions lib/integrity/builder.rb
Expand Up @@ -11,12 +11,8 @@ def initialize(project)
@build = Build.new(:project => project)
end

def build(commit=nil)
if commit
@scm.with_revision(commit) { run_build_script }
else
@scm.with_latest_code { run_build_script }
end
def build(commit='origin/HEAD')
@scm.with_revision(commit) { run_build_script }
@build
ensure
@build.commit = @scm.head
Expand Down
5 changes: 0 additions & 5 deletions lib/integrity/scm/git.rb
Expand Up @@ -9,11 +9,6 @@ def initialize(uri, branch, working_directory)
@working_directory = working_directory
end

def with_latest_code(&block)
fetch_code
chdir(&block)
end

def with_revision(revision, &block)
fetch_code
checkout(revision)
Expand Down
6 changes: 3 additions & 3 deletions spec/builder_spec.rb
Expand Up @@ -18,7 +18,7 @@ def mock_build(messages={})

def mock_scm(messages={})
@scm ||= begin
messages = { :with_latest_code => true, :head => Hash.new }.merge(messages)
messages = { :with_revision => true, :head => Hash.new }.merge(messages)
mock("scm", messages)
end
end
Expand Down Expand Up @@ -62,7 +62,7 @@ def mock_scm(messages={})
before { @builder.stub!(:run_build_script) }

it "should fetch the latest code from the scm and run the build script" do
mock_scm.should_receive(:with_latest_code).and_yield do
mock_scm.should_receive(:with_revision).with('origin/HEAD').and_yield do
@builder.should_receive(:run_build_script)
end
@builder.build
Expand All @@ -88,7 +88,7 @@ def mock_scm(messages={})

it "should save the build even if there's an exception" do
lambda {
mock_scm.should_receive(:with_latest_code).and_raise(RuntimeError)
mock_scm.should_receive(:with_revision).and_raise(RuntimeError)
mock_build.should_receive(:save)
@builder.build
}.should raise_error(RuntimeError)
Expand Down
34 changes: 8 additions & 26 deletions spec/scm/git_spec.rb
Expand Up @@ -82,48 +82,30 @@
end
end

describe "Running code in the context of the most recent checkout" do
before do
@block = lambda { "cuack" }
@git.stub!(:fetch_code)
@git.stub!(:chdir).with(&@block)
end

it "should ensure it has the latest code" do
@git.should_receive(:fetch_code)
@git.with_latest_code(&@block)
end

it "should run the block in the working copy directory" do
@git.should_receive(:chdir).with(&@block).and_yield
@git.with_latest_code(&@block)
end
end

describe 'Running code in the context of a specific revision' do
before do
@block = proc { 'lambda the ultimate' }
describe 'Running code in a specific context using #with_revision' do
before(:each) do
@block = lambda { 'lambda the ultimate' }
@git.stub!(:fetch_code)
@git.stub!(:checkout)
@git.stub!(:chdir).with(&@block)
end

it 'should fetch the lastest code' do
it "should fetch the latest code" do
@git.should_receive(:fetch_code)
@git.with_revision('4d0cfafd569ef60d0c578bf8a9d51f9582612f03', &@block)
@git.with_revision('HEAD', &@block)
end

it 'should revert the working directory to the given commit' do
it 'should checkout the given revision' do
@git.should_receive(:checkout).with('4d0cfafd569ef60d0c578bf8a9d51f9582612f03')
@git.with_revision('4d0cfafd569ef60d0c578bf8a9d51f9582612f03', &@block)
end

it 'should run the block in the working directory' do
it "should run the block in the working copy directory" do
@git.should_receive(:chdir).with(&@block).and_yield
@git.with_revision('4d0cfafd569ef60d0c578bf8a9d51f9582612f03', &@block)
end

it 'should ensure that it checkout origin/HEAD after' do
it 'should ensure it checkout origin/HEAD' do
@git.should_receive(:checkout).with('origin/HEAD')
@git.with_revision('4d0cfafd569ef60d0c578bf8a9d51f9582612f03', &@block)
end
Expand Down

0 comments on commit 31813ae

Please sign in to comment.