Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 82 additions & 82 deletions spec/auto_tagger/base_spec.rb

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions spec/auto_tagger/capistrano_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,68 @@
describe "#ref" do
it "returns the specified branch when passed the :head variable" do
helper = AutoTagger::CapistranoHelper.new :branch => "release", :head => nil
helper.ref.should == "release"
expect(helper.ref).to eq("release")
end

it "returns the specified tag" do
helper = AutoTagger::CapistranoHelper.new :tag => "v0.1.7"
helper.ref.should == "v0.1.7"
expect(helper.ref).to eq("v0.1.7")
end

it "returns the specified ref" do
helper = AutoTagger::CapistranoHelper.new :ref => "refs/auto_tags/ci"
helper.ref.should == "refs/auto_tags/ci"
expect(helper.ref).to eq("refs/auto_tags/ci")
end

it "returns the sha of the last ref from that stage" do
helper = AutoTagger::CapistranoHelper.new({})
ref = mock(AutoTagger::Git::Ref, :sha => "abc123")
auto_tagger = mock AutoTagger::Base, :last_ref_from_previous_stage => ref
helper.stub(:auto_tagger) { auto_tagger }
helper.ref.should == "abc123"
ref = double(AutoTagger::Git::Ref, :sha => "abc123")
auto_tagger = double AutoTagger::Base, :last_ref_from_previous_stage => ref
allow(helper).to receive(:auto_tagger) { auto_tagger }
expect(helper.ref).to eq("abc123")
end

it "returns the branch when specified" do
helper = AutoTagger::CapistranoHelper.new :branch => "release"
helper.ref.should == "release"
expect(helper.ref).to eq("release")
end
end

describe "#auto_tagger" do
it "returns an AutoTagger::Base object with the correct options" do
helper = AutoTagger::CapistranoHelper.new({})
helper.stub(:auto_tagger_options).and_return({:foo => "bar"})
AutoTagger::Base.should_receive(:new).with({:foo => "bar"})
allow(helper).to receive(:auto_tagger_options).and_return({:foo => "bar"})
expect(AutoTagger::Base).to receive(:new).with({:foo => "bar"})
helper.auto_tagger
end
end

describe "#auto_tagger_options" do
it "includes :stage from :auto_tagger_stage, :stage" do
helper = AutoTagger::CapistranoHelper.new :stage => "demo"
helper.auto_tagger_options[:stage].should == "demo"
expect(helper.auto_tagger_options[:stage]).to eq("demo")

helper = AutoTagger::CapistranoHelper.new :auto_tagger_stage => "demo"
helper.auto_tagger_options[:stage].should == "demo"
expect(helper.auto_tagger_options[:stage]).to eq("demo")

helper = AutoTagger::CapistranoHelper.new :auto_tagger_stage => "demo", :stage => "ci"
helper.auto_tagger_options[:stage].should == "demo"
expect(helper.auto_tagger_options[:stage]).to eq("demo")
end

it "includes stages" do
helper = AutoTagger::CapistranoHelper.new :auto_tagger_stages => ["demo"]
helper.auto_tagger_options[:stages].should == ["demo"]
expect(helper.auto_tagger_options[:stages]).to eq(["demo"])
end

it "includes :auto_tagger_working_directory" do
helper = AutoTagger::CapistranoHelper.new :auto_tagger_working_directory => "/foo"
helper.auto_tagger_options[:path].should == "/foo"
expect(helper.auto_tagger_options[:path]).to eq("/foo")
end

it "includes and deprecates :working_directory" do
AutoTagger::Deprecator.should_receive(:warn)
expect(AutoTagger::Deprecator).to receive(:warn)
helper = AutoTagger::CapistranoHelper.new :working_directory => "/foo"
helper.auto_tagger_options[:path].should == "/foo"
expect(helper.auto_tagger_options[:path]).to eq("/foo")
end

[
Expand All @@ -84,16 +84,16 @@
].each do |key|
it "includes :#{key} when specified" do
helper = AutoTagger::CapistranoHelper.new({})
helper.auto_tagger_options.should_not have_key(key)
expect(helper.auto_tagger_options).not_to have_key(key)

helper = AutoTagger::CapistranoHelper.new(:"auto_tagger_#{key}" => "value")
helper.auto_tagger_options.should have_key(key)
helper.auto_tagger_options[key].should == "value"
expect(helper.auto_tagger_options).to have_key(key)
expect(helper.auto_tagger_options[key]).to eq("value")
end
end

it "accepts capistrano's dry_run" do
AutoTagger::CapistranoHelper.new(:dry_run => "shazbot").auto_tagger_options[:dry_run].should == "shazbot"
expect(AutoTagger::CapistranoHelper.new(:dry_run => "shazbot").auto_tagger_options[:dry_run]).to eq("shazbot")
end

[
Expand All @@ -111,31 +111,31 @@
].each do |dry_run, auto_tagger_dry_run, preferred|
it "prefers auto_tagger_dry_run=#{auto_tagger_dry_run.inspect} to dry_run=#{dry_run.inspect}" do
helper = AutoTagger::CapistranoHelper.new(:dry_run => dry_run, :auto_tagger_dry_run => auto_tagger_dry_run)
helper.auto_tagger_options[:dry_run].should == preferred
expect(helper.auto_tagger_options[:dry_run]).to eq(preferred)
end
end
end

describe "#stages" do
it "understands :stages" do
helper = AutoTagger::CapistranoHelper.new :stages => ["demo"]
helper.stages.should == ["demo"]
expect(helper.stages).to eq(["demo"])
end

it "understands :auto_tagger_stages" do
helper = AutoTagger::CapistranoHelper.new :auto_tagger_stages => ["demo"]
helper.auto_tagger_options[:stages].should == ["demo"]
expect(helper.auto_tagger_options[:stages]).to eq(["demo"])
end

it "understands and deprecates :autotagger_stages" do
AutoTagger::Deprecator.should_receive(:warn)
expect(AutoTagger::Deprecator).to receive(:warn)
helper = AutoTagger::CapistranoHelper.new :autotagger_stages => ["demo"]
helper.stages.should == ["demo"]
expect(helper.stages).to eq(["demo"])
end

it "makes all stages strings" do
helper = AutoTagger::CapistranoHelper.new :auto_tagger_stages => [:demo]
helper.stages.should == ["demo"]
expect(helper.stages).to eq(["demo"])
end
end

Expand Down
70 changes: 35 additions & 35 deletions spec/auto_tagger/command_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,103 @@
describe "#execute" do
it "runs the version command" do
command_line = AutoTagger::CommandLine.new ["version"]
command_line.execute.first.should be_true
command_line.execute.last.should include(AutoTagger::VERSION)
expect(command_line.execute.first).to eq(true)
expect(command_line.execute.last).to include(AutoTagger::VERSION)
end

it "runs the help command" do
command_line = AutoTagger::CommandLine.new ["help"]
command_line.execute.last.should include("USAGE")
expect(command_line.execute.last).to include("USAGE")
end

describe "#cleanup" do
it "runs the cleanup command with a stage" do
command_line = AutoTagger::CommandLine.new ["cleanup"]
tagger = mock(AutoTagger::Base, :cleanup => 7)
AutoTagger::Base.should_receive(:new).and_return(tagger)
command_line.execute.last.should include("7")
tagger = double(AutoTagger::Base, :cleanup => 7)
expect(AutoTagger::Base).to receive(:new).and_return(tagger)
expect(command_line.execute.last).to include("7")
end

it "prints a friendly error message when no stage is provided" do
command_line = AutoTagger::CommandLine.new ["cleanup"]
AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
command_line.execute.last.should include("You must provide a stage")
expect(AutoTagger::Base).to receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
expect(command_line.execute.last).to include("You must provide a stage")
end
end

describe "#delete_locally" do
it "runs the delete_locally command" do
command_line = AutoTagger::CommandLine.new ["delete_locally"]
tagger = mock(AutoTagger::Base, :delete_locally => 7)
AutoTagger::Base.should_receive(:new).and_return(tagger)
command_line.execute.last.should include("7")
tagger = double(AutoTagger::Base, :delete_locally => 7)
expect(AutoTagger::Base).to receive(:new).and_return(tagger)
expect(command_line.execute.last).to include("7")
end

it "prints a friendly error message when no stage is provided" do
command_line = AutoTagger::CommandLine.new ["delete_locally"]
AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
command_line.execute.last.should include("You must provide a stage")
expect(AutoTagger::Base).to receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
expect(command_line.execute.last).to include("You must provide a stage")
end
end

describe "#delete_on_remote" do
it "runs the delete_on_remote command" do
command_line = AutoTagger::CommandLine.new ["delete_on_remote"]
tagger = mock(AutoTagger::Base, :delete_on_remote => 7)
AutoTagger::Base.should_receive(:new).and_return(tagger)
command_line.execute.last.should include("7")
tagger = double(AutoTagger::Base, :delete_on_remote => 7)
expect(AutoTagger::Base).to receive(:new).and_return(tagger)
expect(command_line.execute.last).to include("7")
end

it "prints a friendly error message when no stage is provided" do
command_line = AutoTagger::CommandLine.new ["delete_on_remote"]
AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
command_line.execute.last.should include("You must provide a stage")
expect(AutoTagger::Base).to receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
expect(command_line.execute.last).to include("You must provide a stage")
end
end

describe "#list" do
it "runs the list command" do
command_line = AutoTagger::CommandLine.new ["list"]
tagger = mock(AutoTagger::Base, :list => ["foo", "bar"])
AutoTagger::Base.should_receive(:new).and_return(tagger)
command_line.execute.last.should include("foo", "bar")
tagger = double(AutoTagger::Base, :list => ["foo", "bar"])
expect(AutoTagger::Base).to receive(:new).and_return(tagger)
expect(command_line.execute.last).to include("foo", "bar")
end

it "prints a friendly error message when no stage is provided" do
command_line = AutoTagger::CommandLine.new ["list"]
AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
command_line.execute.last.should include("You must provide a stage")
expect(AutoTagger::Base).to receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
expect(command_line.execute.last).to include("You must provide a stage")
end
end

it "runs the config command" do
command_line = AutoTagger::CommandLine.new ["config"]
config = mock(AutoTagger::Configuration, :settings => {"foo" => "bar"})
AutoTagger::Configuration.should_receive(:new).and_return(config)
command_line.execute.last.should include("foo", "bar")
config = double(AutoTagger::Configuration, :settings => {"foo" => "bar"})
expect(AutoTagger::Configuration).to receive(:new).and_return(config)
expect(command_line.execute.last).to include("foo", "bar")
end

describe "#create" do
it "runs the create command" do
command_line = AutoTagger::CommandLine.new ["create"]
tagger = mock(AutoTagger::Base, :create_ref => mock(AutoTagger::Git::Ref, :name => "refs/tags"))
AutoTagger::Base.should_receive(:new).and_return(tagger)
command_line.execute.last.should include("refs/tags")
tagger = double(AutoTagger::Base, :create_ref => double(AutoTagger::Git::Ref, :name => "refs/tags"))
expect(AutoTagger::Base).to receive(:new).and_return(tagger)
expect(command_line.execute.last).to include("refs/tags")
end

it "includes a deprecation command when necessary" do
command_line = AutoTagger::CommandLine.new ["ci"]
tagger = mock(AutoTagger::Base, :create_ref => mock(AutoTagger::Git::Ref, :name => "refs/tags"))
AutoTagger::Base.should_receive(:new).and_return(tagger)
tagger = double(AutoTagger::Base, :create_ref => double(AutoTagger::Git::Ref, :name => "refs/tags"))
expect(AutoTagger::Base).to receive(:new).and_return(tagger)
result = command_line.execute.last
result.should include("DEPRECATION")
result.should include("refs/tags")
expect(result).to include("DEPRECATION")
expect(result).to include("refs/tags")
end

it "prints a friendly error message when no stage is provided" do
command_line = AutoTagger::CommandLine.new ["create"]
AutoTagger::Base.should_receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
command_line.execute.last.should include("You must provide a stage")
expect(AutoTagger::Base).to receive(:new).and_raise(AutoTagger::Base::StageCannotBeBlankError)
expect(command_line.execute.last).to include("You must provide a stage")
end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/auto_tagger/commander_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
describe "#read" do
it "execute the command and returns the results" do
commander = AutoTagger::Commander.new("/foo", false)
commander.should_receive(:`).with('cd "/foo" && ls')
expect(commander).to receive(:`).with('cd "/foo" && ls')
commander.read("ls")
end

it "puts the response when it's verbose" do
commander = AutoTagger::Commander.new("/foo", true)
commander.stub(:`)
commander.should_receive(:puts).with('cd "/foo" && ls')
allow(commander).to receive(:`)
expect(commander).to receive(:puts).with('cd "/foo" && ls')
commander.read("ls")
end
end

describe "#execute" do
it "executes and doesn't return anything" do
commander = AutoTagger::Commander.new("/foo", false)
commander.should_receive(:system).with('cd "/foo" && ls')
expect(commander).to receive(:system).with('cd "/foo" && ls')
commander.execute("ls")
end

it "puts the response when it's verbose" do
commander = AutoTagger::Commander.new("/foo", true)
commander.stub(:system)
commander.should_receive(:puts).with('cd "/foo" && ls')
allow(commander).to receive(:system)
expect(commander).to receive(:puts).with('cd "/foo" && ls')
commander.execute("ls")
end
end

describe "#print" do
it "returns the command to be run" do
commander = AutoTagger::Commander.new("/foo", false)
commander.should_receive(:puts).with('cd "/foo" && ls')
expect(commander).to receive(:puts).with('cd "/foo" && ls')
commander.print("ls")
end
end
Expand Down
Loading