Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Let's use Mocha.

  • Loading branch information...
commit 57a4c7f2ebd03c253f3643f0fb0f924f5cf56a07 1 parent bd93c9d
@gabebw gabebw authored
View
1  kumade.gemspec
@@ -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
20 spec/kumade/base_spec.rb
@@ -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,7 +28,7 @@
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
@@ -36,8 +36,8 @@
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
@@ -45,8 +45,8 @@
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
10 spec/kumade/cli_spec.rb
@@ -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!"
View
34 spec/kumade/deployer_spec.rb
@@ -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,7 +48,7 @@
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
@@ -56,7 +56,7 @@
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
16 spec/kumade/git_spec.rb
@@ -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
34 spec/kumade/heroku_spec.rb
@@ -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
View
116 spec/kumade/packager_spec.rb
@@ -1,5 +1,7 @@
require 'spec_helper'
+require 'jammit'
+
shared_context "with a fake Git" do
let(:git) { stub() }
subject { Kumade::Packager.new(git) }
@@ -10,67 +12,67 @@
context "with Jammit installed" do
it "calls package_with_jammit" do
- subject.should_receive(:package_with_jammit)
+ subject.expects(:package_with_jammit)
subject.run
end
end
context "with Jammit not installed" do
- before { subject.stub(:jammit_installed? => false) }
+ before { subject.stubs(:jammit_installed? => false) }
it "does not call package_with_jammit" do
- subject.should_not_receive(:package_with_jammit)
+ subject.expects(:package_with_jammit).never
subject.run
end
end
context "with More installed" do
before do
- subject.stub(:jammit_installed? => false)
- subject.stub(:more_installed? => true)
+ subject.stubs(:jammit_installed? => false)
+ subject.stubs(:more_installed? => true)
end
it "calls package_with_more" do
- subject.should_receive(:package_with_more)
+ subject.expects(:package_with_more)
subject.run
end
end
context "with More not installed" do
before do
- subject.stub(:jammit_installed? => false)
- subject.stub(:more_installed? => false)
+ subject.stubs(:jammit_installed? => false)
+ subject.stubs(:more_installed? => false)
end
it "does not call package_with_more" do
- subject.should_not_receive(:package_with_more)
+ subject.expects(:package_with_more).never
subject.run
end
end
context "with custom rake task installed" do
before do
- subject.stub(:jammit_installed? => false,
+ subject.stubs(:jammit_installed? => false,
:more_installed? => false,
:invoke_custom_task => nil,
:custom_task? => true)
end
it "invokes custom task" do
- subject.should_receive(:invoke_custom_task)
+ subject.expects(:invoke_custom_task)
subject.run
end
end
context "with custom rake task not installed" do
before do
- subject.stub(:jammit_installed? => false,
+ subject.stubs(:jammit_installed? => false,
:more_installed? => false,
:invoke_custom_task => nil,
:custom_task? => false)
end
it "does not invoke custom task" do
- subject.should_not_receive(:invoke_custom_task)
+ subject.expects(:invoke_custom_task).never
subject.run
end
end
@@ -80,15 +82,16 @@
include_context "with a fake Git"
before do
- subject.stub(:say)
- Rake::Task.stub(:[] => task)
+ subject.stubs(:say)
+ Rake::Task.stubs(:[] => task)
end
- let(:task) { stub('task', :invoke => nil) }
+ let(:task) { stub('kumade:before_asset_compilation task', :invoke => nil) }
it "calls deploy task" do
- Rake::Task.should_receive(:[]).with("kumade:before_asset_compilation")
- task.should_receive(:invoke)
+ task.expects(:invoke)
+ Rake::Task.expects(:[]).with("kumade:before_asset_compilation").returns(task)
+
subject.invoke_custom_task
end
end
@@ -103,9 +106,9 @@
it "returns true if it task found" do
namespace :kumade do
task :before_asset_compilation do
-
end
end
+
subject.custom_task?.should be_true
end
@@ -118,40 +121,39 @@
include_context "with a fake Git"
before do
- subject.stub(:git_add_and_commit_all_assets_in)
- subject.stub(:say)
- Jammit.stub(:package!)
+ subject.stubs(:git_add_and_commit_all_assets_in)
+ subject.stubs(:say)
+ Jammit.stubs(:package!)
end
it "calls Jammit.package!" do
- Jammit.should_receive(:package!).once
+ Jammit.expects(:package!).once
subject.package_with_jammit
end
context "with updated assets" do
- before { subject.stub(:git => mock(:dirty? => true)) }
+ before { subject.git.stubs(:dirty? => true) }
it "prints the correct message" do
- subject.should_receive(:success).with("Packaged assets with Jammit")
+ subject.expects(:success).with("Packaged assets with Jammit")
subject.package_with_jammit
end
it "calls git_add_and_commit_all_assets_in" do
- subject.stub(:jammit_assets_path => 'jammit-assets')
- subject.should_receive(:git_add_and_commit_all_assets_in).
+ subject.stubs(:jammit_assets_path => 'jammit-assets')
+ subject.expects(:git_add_and_commit_all_assets_in).
with('jammit-assets').
- and_return(true)
+ returns(true)
subject.package_with_jammit
end
end
it "prints an error if packaging failed" do
- Jammit.stub(:package!) do
- raise Jammit::MissingConfiguration.new("random Jammit error")
- end
- subject.should_receive(:error).with("Error: Jammit::MissingConfiguration: random Jammit error")
+ Jammit.expects(:package!).raises(Jammit::MissingConfiguration.new("random Jammit error"))
+
+ subject.expects(:error).with("Error: Jammit::MissingConfiguration: random Jammit error")
subject.package_with_jammit
end
@@ -161,33 +163,35 @@
include_context "with a fake Git"
before do
- subject.stub(:git_add_and_commit_all_assets_in => true,
+ subject.stubs(:git_add_and_commit_all_assets_in => true,
:more_assets_path => 'assets')
- subject.stub(:say)
+ subject.stubs(:say)
end
it "calls the more:generate task" do
- git.should_receive(:dirty?).and_return(true)
- subject.should_receive(:run).with("bundle exec rake more:generate")
+ git.expects(:dirty?).returns(true)
+ subject.expects(:run).with("bundle exec rake more:generate")
subject.package_with_more
end
context "with changed assets" do
+ before do
+ git.stubs(:dirty? => true)
+ end
+
it "prints a success message" do
- subject.stub(:run).with("bundle exec rake more:generate")
- subject.stub(:git => mock(:dirty? => true))
- subject.should_receive(:success).with("Packaged assets with More")
+ subject.stubs(:run).with("bundle exec rake more:generate")
+ subject.expects(:success).with("Packaged assets with More")
subject.package_with_more
end
it "calls git_add_and_commit_all_assets_in if assets were added" do
- subject.stub(:git => mock(:dirty? => true),
- :more_assets_path => 'blerg')
- subject.stub(:run).with("bundle exec rake more:generate")
- subject.should_receive(:git_add_and_commit_all_assets_in).
+ subject.stubs(:more_assets_path => 'blerg')
+ subject.stubs(:run).with("bundle exec rake more:generate")
+ subject.expects(:git_add_and_commit_all_assets_in).
with('blerg').
- and_return(true)
+ returns(true)
subject.package_with_more
end
@@ -195,30 +199,26 @@
context "with no changed assets" do
it "prints no message" do
- subject.stub(:run).with("bundle exec rake more:generate")
- subject.stub(:git => mock(:dirty? => false))
- subject.should_not_receive(:say)
+ subject.stubs(:run).with("bundle exec rake more:generate")
+ subject.stubs(:git => mock(:dirty? => false))
+ subject.expects(:say).never
subject.package_with_more
end
it "does not call git_add_and_commit_all_more_assets" do
- subject.stub(:run).with("bundle exec rake more:generate")
- subject.stub(:git => mock(:dirty? => false))
- subject.should_not_receive(:git_add_and_commit_all_assets_in)
+ subject.stubs(:run).with("bundle exec rake more:generate")
+ subject.stubs(:git => mock(:dirty? => false))
+ subject.expects(:git_add_and_commit_all_assets_in).never
subject.package_with_more
end
end
it "prints an error if packaging failed" do
- subject.stub(:run) do |arg|
- if arg == "bundle exec rake more:generate"
- raise "blerg"
- end
- end
+ subject.stubs(:run).with("bundle exec rake more:generate").raises("blerg")
- subject.should_receive(:error).with("Error: RuntimeError: blerg")
+ subject.expects(:error).with("Error: RuntimeError: blerg")
subject.package_with_more
end
@@ -228,7 +228,7 @@
include_context "with a fake Git"
it "should call git.add_and_commit_all_in" do
- git.should_receive(:add_and_commit_all_in).with("dir", 'deploy', 'Compiled assets', "Added and committed all assets", "couldn't commit assets")
+ git.expects(:add_and_commit_all_in).with("dir", 'deploy', 'Compiled assets', "Added and committed all assets", "couldn't commit assets")
subject.git_add_and_commit_all_assets_in("dir")
end
end
@@ -238,7 +238,7 @@
let(:packager) { Kumade::Packager.new(git) }
before do
- Jammit.stub(:package_path).and_return('blerg')
+ Jammit.stubs(:package_path).returns('blerg')
end
subject { packager.jammit_assets_path }
View
2  spec/spec_helper.rb
@@ -23,7 +23,7 @@ def remove_remote(remote_name)
Dir[spec_dir.join('support', '**')].each {|f| require File.expand_path(f) }
RSpec.configure do |config|
- config.mock_with :rspec
+ config.mock_with :mocha
config.color_enabled = true
config.include Rake::DSL if defined?(Rake::DSL)
View
17 spec/support/heroku.rb
@@ -1,12 +1,12 @@
shared_context "when on Cedar" do
- let(:cocaine_mock) { mock("Cocaine::CommandLine") }
+ let(:command_line) { mock("Cocaine::CommandLine") }
before do
- Cocaine::CommandLine.should_receive(:new).
+ Cocaine::CommandLine.expects(:new).
with("bundle exec heroku stack --remote staging").
- and_return(cocaine_mock)
+ returns(command_line)
- cocaine_mock.should_receive(:run).and_return(%{
+ command_line.expects(:run).returns(%{
aspen-mri-1.8.6
bamboo-mri-1.9.2
bamboo-ree-1.8.7
@@ -16,13 +16,14 @@
end
shared_context "when not on Cedar" do
- let(:cocaine_mock) { mock("Cocaine::CommandLine") }
+ let(:command_line) { mock("Cocaine::CommandLine") }
before do
- Cocaine::CommandLine.should_receive(:new).
+ Cocaine::CommandLine.expects(:new).
with("bundle exec heroku stack --remote staging").
- and_return(cocaine_mock)
- cocaine_mock.should_receive(:run).and_return(%{
+ returns(command_line)
+
+ command_line.expects(:run).returns(%{
aspen-mri-1.8.6
* bamboo-mri-1.9.2
bamboo-ree-1.8.7

3 comments on commit 57a4c7f

@tapajos

Why this change?

@joshuaclayton

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

@gabebw
Admin

@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.
Something went wrong with that request. Please try again.