Permalink
Browse files

Let's use Mocha.

  • Loading branch information...
1 parent bd93c9d commit 57a4c7f2ebd03c253f3643f0fb0f924f5cf56a07 Gabe Berke-Williams committed Sep 13, 2011
View
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('cucumber', '~> 1.0.2')
s.add_development_dependency('aruba', '~> 0.4.3')
s.add_development_dependency('jammit', '~> 0.6.3')
+ s.add_development_dependency('bourne')
end
View
@@ -8,7 +8,7 @@
it { should respond_to(:error) }
it "prints its message and raises its message" do
- STDOUT.should_receive(:puts).with(/I'm an error!/)
+ STDOUT.expects(:puts).with(regexp_matches(/I'm an error!/))
lambda { subject.error("I'm an error!") }.should raise_error(Kumade::DeploymentError)
end
@@ -19,7 +19,7 @@
let(:error_message) { "dummy error message" }
before do
- STDOUT.should_receive(:puts).with(/#{command}/)
+ STDOUT.expects(:puts).with(regexp_matches(/#{command}/))
end
context "when pretending" do
@@ -28,25 +28,25 @@
end
it "does not run the command" do
- subject.should_not_receive(:run)
+ subject.expects(:run).never
subject.run_or_error("dummy command", "dummy error message")
end
end
context "when not pretending" do
context "when it runs successfully" do
it "does not print an error" do
- STDOUT.should_not_receive(:puts).with(/#{error_message}/)
- Cocaine::CommandLine.stub(:new).and_return(stub(:run => true))
+ STDOUT.expects(:puts).with(regexp_matches(/#{error_message}/)).never
+ Cocaine::CommandLine.stubs(:new).returns(stub(:run => true))
subject.run_or_error(command, error_message)
end
end
context "when it does not run successfully " do
it "should call CommandLine.run and error with error_message" do
- subject.should_receive(:run).and_return(false)
- subject.should_receive(:error).with(error_message)
+ subject.expects(:run).returns(false)
+ subject.expects(:error).with(error_message)
subject.run_or_error(command, error_message)
end
@@ -59,12 +59,12 @@
let(:command) { "command" }
before do
- Cocaine::CommandLine.stub(:new).with(command).and_return(command_line_mock)
+ Cocaine::CommandLine.stubs(:new).with(command).returns(command_line_mock)
end
context "when not successful" do
before do
- command_line_mock.should_receive(:run)
+ command_line_mock.expects(:run)
end
it "returns true" do
@@ -74,7 +74,7 @@
context "when successful" do
before do
- command_line_mock.should_receive(:run).and_raise(Cocaine::ExitStatusError)
+ command_line_mock.expects(:run).raises(Cocaine::ExitStatusError)
end
it "returns false" do
View
@@ -20,7 +20,7 @@
end
it "deploys" do
- deployer_instance.should_receive(:deploy)
+ deployer_instance.expects(:deploy)
subject
end
end
@@ -48,7 +48,7 @@
end
it "deploys" do
- deployer_instance.should_receive(:deploy)
+ deployer_instance.expects(:deploy)
subject
end
end
@@ -72,7 +72,7 @@
let(:output) { StringIO.new }
it 'does not let anything get printed' do
- stdout.should_not_receive(:print)
+ stdout.expects(:print).never
Kumade::CLI.swapping_stdout_for(output) do
$stdout.puts "Hello, you can't see me."
@@ -83,7 +83,7 @@
end
it 'dumps the output stash to real stdout when an error happens' do
- stdout.should_receive(:print)
+ stdout.expects(:print)
Kumade::CLI.swapping_stdout_for(output) do
$stdout.puts "Hello, you can see me!"
@@ -93,7 +93,7 @@
context "in print output mode" do
it 'prints everything' do
- stdout.should_receive(:puts)
+ stdout.expects(:puts)
Kumade::CLI.swapping_stdout_for(output, true) do
$stdout.puts "Hello, you can see me!"
@@ -6,9 +6,9 @@
let(:git) { subject.git }
it "calls the correct methods" do
- git.should_receive(:ensure_clean_git)
- subject.should_receive(:package_assets)
- git.should_receive(:push).with(subject.git.current_branch)
+ git.expects(:ensure_clean_git)
+ subject.expects(:package_assets)
+ git.expects(:push).with(subject.git.current_branch)
subject.pre_deploy
end
@@ -18,23 +18,23 @@
let(:remote_name) { 'staging' }
before do
- STDOUT.stub(:puts)
+ STDOUT.stubs(:puts)
force_add_heroku_remote(remote_name)
end
it "calls the correct methods" do
- subject.should_receive(:pre_deploy)
- subject.heroku.should_receive(:sync)
- subject.heroku.should_receive(:migrate_database)
- subject.should_receive(:post_deploy)
+ subject.expects(:pre_deploy)
+ subject.heroku.expects(:sync)
+ subject.heroku.expects(:migrate_database)
+ subject.expects(:post_deploy)
subject.deploy
end
it "calls post_deploy if deploy fails" do
- subject.git.stub(:heroku_remote?).and_raise(RuntimeError)
+ subject.git.stubs(:heroku_remote?).raises(RuntimeError)
- subject.should_receive(:post_deploy)
+ subject.expects(:post_deploy)
subject.deploy
end
@@ -48,15 +48,15 @@
end
it "pushes the current branch to github" do
- subject.git.should_receive(:push).with(new_branch)
+ subject.git.expects(:push).with(new_branch)
subject.sync_github
end
end
describe Kumade::Deployer, "#ensure_clean_git" do
it "calls git.ensure_clean_git" do
- subject.git.should_receive(:ensure_clean_git)
+ subject.git.expects(:ensure_clean_git)
subject.ensure_clean_git
end
end
@@ -70,14 +70,16 @@
end
context "when the remote points to Heroku" do
+ before { STDOUT.stubs(:puts) }
+
it "does not print an error" do
- STDOUT.should_not_receive(:puts).with(/==> !/)
+ STDOUT.expects(:puts).with(regexp_matches(/==> !/)).never
subject.ensure_heroku_remote_exists
end
it "prints a success message" do
- STDOUT.should_receive(:puts).with(/#{environment} is a Heroku remote/)
+ STDOUT.expects(:puts).with(regexp_matches(/#{environment} is a Heroku remote/))
subject.ensure_heroku_remote_exists
end
@@ -89,7 +91,7 @@
end
it "prints an error" do
- STDOUT.should_receive(:puts).with(/Cannot deploy: "#{environment}" remote does not exist/)
+ STDOUT.expects(:puts).with(regexp_matches(/Cannot deploy: "#{environment}" remote does not exist/))
lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
end
@@ -104,7 +106,7 @@
end
it "prints an error" do
- STDOUT.should_receive(:puts).with(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/)
+ STDOUT.expects(:puts).with(regexp_matches(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/))
lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
end
View
@@ -68,16 +68,16 @@
let(:branch) { "branch" }
before do
- Cocaine::CommandLine.should_receive(:new).with("git show-ref #{branch}").and_return(command_line_mock)
+ Cocaine::CommandLine.expects(:new).with("git show-ref #{branch}").returns(command_line_mock)
end
it "returns true when the branch exists" do
- command_line_mock.should_receive(:run)
+ command_line_mock.expects(:run)
subject.branch_exist?("branch").should be_true
end
it "returns false if the branch doesn't exist" do
- command_line_mock.should_receive(:run).and_raise(Cocaine::ExitStatusError)
+ command_line_mock.expects(:run).raises(Cocaine::ExitStatusError)
subject.branch_exist?("branch").should be_false
end
@@ -88,11 +88,11 @@
let(:command_line) { mock("CommandLine instance") }
before do
- command_line.should_receive(:run).and_raise(Cocaine::ExitStatusError)
+ command_line.expects(:run).raises(Cocaine::ExitStatusError)
- Cocaine::CommandLine.should_receive(:new).
+ Cocaine::CommandLine.expects(:new).
with("git diff --exit-code").
- and_return(command_line)
+ returns(command_line)
end
it "returns true" do
@@ -102,9 +102,9 @@
context "when clean" do
before do
- Cocaine::CommandLine.should_receive(:new).
+ Cocaine::CommandLine.expects(:new).
with("git diff --exit-code").
- and_return(mock(:run => true))
+ returns(mock(:run => true))
end
it "returns false" do
View
@@ -14,8 +14,8 @@
end
it "creates and pushes the deploy branch" do
- subject.git.should_receive(:create).with("deploy")
- subject.git.should_receive(:push).with("deploy:master", environment, true)
+ subject.git.expects(:create).with("deploy")
+ subject.git.expects(:push).with("deploy:master", environment, true)
subject.sync
end
end
@@ -24,30 +24,30 @@
let(:environment) { 'staging' }
before do
- STDOUT.stub(:puts)
+ STDOUT.stubs(:puts)
force_add_heroku_remote(environment)
end
it "runs db:migrate with the correct app" do
- subject.should_receive(:heroku).with("rake db:migrate")
+ subject.expects(:heroku).with("rake db:migrate")
subject.migrate_database
end
context "when pretending" do
before do
- STDOUT.stub(:puts)
+ STDOUT.stubs(:puts)
Kumade.configuration.pretending = true
end
it "does not run the command" do
- subject.should_not_receive(:heroku)
+ subject.expects(:heroku).never
subject.migrate_database
end
it "prints a message" do
- STDOUT.should_receive(:puts).with(/Migrated #{environment}/)
+ STDOUT.expects(:puts).with(regexp_matches(/Migrated #{environment}/))
subject.migrate_database
end
@@ -58,16 +58,16 @@
let(:command_line_instance) { stub("Cocaine::CommandLine instance", :run => true) }
before do
- STDOUT.stub(:puts)
+ STDOUT.stubs(:puts)
end
context "when on Cedar" do
include_context "when on Cedar"
it "runs commands with `run`" do
- Cocaine::CommandLine.should_receive(:new).
- with(/bundle exec heroku run/).
- and_return(command_line_instance)
+ Cocaine::CommandLine.expects(:new).
+ with(regexp_matches(/bundle exec heroku run/)).
+ returns(command_line_instance)
subject.heroku("rake")
end
@@ -77,9 +77,9 @@
include_context "when not on Cedar"
it "runs commands without `run`" do
- Cocaine::CommandLine.should_receive(:new).
- with(/bundle exec heroku rake/).
- and_return(command_line_instance)
+ Cocaine::CommandLine.expects(:new).
+ with(regexp_matches(/bundle exec heroku rake/)).
+ returns(command_line_instance)
subject.heroku("rake")
end
@@ -105,12 +105,12 @@
end
describe Kumade::Heroku, "#delete_deploy_branch" do
- before { STDOUT.stub(:puts) }
+ before { STDOUT.stubs(:puts) }
it "deletes the deploy branch" do
- Cocaine::CommandLine.should_receive(:new).
+ Cocaine::CommandLine.expects(:new).
with("git checkout master && git branch -D deploy").
- and_return(stub(:run => true))
+ returns(stub(:run => true))
subject.delete_deploy_branch
end
end
Oops, something went wrong.

3 comments on commit 57a4c7f

Contributor

tapajos replied Sep 13, 2011

Why this change?

Owner

joshuaclayton replied Sep 13, 2011

hooray mocha! I love mocha! mocha is the best!

Contributor

gabebw replied Sep 14, 2011

@tapajos: because I think it's a cleaner and less verbose syntax, and because I want to use bourne.
@joshuaclayton: I wish I could favorite a comment.

Please sign in to comment.