Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Switch to Rspec3
Browse files Browse the repository at this point in the history
  • Loading branch information
omockler committed Dec 12, 2014
1 parent 447bfee commit 4b6de40
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 92 deletions.
2 changes: 1 addition & 1 deletion fourchette.gemspec
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'foreman'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rspec', '~> 2.14.1'
spec.add_development_dependency 'rspec', '~> 3.1.0'
spec.add_development_dependency 'guard-rspec'
spec.add_development_dependency 'terminal-notifier-guard'
spec.add_development_dependency 'coveralls'
Expand Down
30 changes: 15 additions & 15 deletions spec/lib/fourchette/fork_spec.rb
Expand Up @@ -25,8 +25,8 @@

describe '#create' do
it 'calls #update and #create_unless_exists' do
subject.should_receive(:create_unless_exists)
subject.should_receive(:update)
expect(subject).to receive(:create_unless_exists)
expect(subject).to receive(:update)
subject.create
end
end
Expand All @@ -38,46 +38,46 @@

context 'app does NOT exists' do
before do
Fourchette::Heroku.any_instance.stub(:app_exists?).and_return(false)
allow_any_instance_of(Fourchette::Heroku).to receive(:app_exists?).and_return(false)
end

it 'calls the fork creation' do
subject.stub(:post_fork_url)
Fourchette::Heroku.any_instance.should_receive(:fork)
allow(subject).to receive(:post_fork_url)
expect_any_instance_of(Fourchette::Heroku).to receive(:fork)
.with('my-heroku-app-name', fork_name)
end

it 'post the URL to the fork on the GitHub PR' do
Fourchette::Heroku.any_instance.stub(:fork)
Fourchette::Heroku.any_instance.stub_chain(:client, :app, :info)
allow_any_instance_of(Fourchette::Heroku).to receive(:fork)
allow_any_instance_of(Fourchette::Heroku).to receive_message_chain(:client, :app, :info)
.and_return('web_url' => 'rainforestqa.com')
Fourchette::GitHub.any_instance.should_receive(:comment_pr)
expect_any_instance_of(Fourchette::GitHub).to receive(:comment_pr)
.with(1, 'Test URL: rainforestqa.com')
end
end

context 'app DOES exists' do
before do
Fourchette::Heroku.any_instance.stub(:app_exists?).and_return(true)
allow_any_instance_of(Fourchette::Heroku).to receive(:app_exists?).and_return(true)
end

it 'does nothing' do
Fourchette::GitHub.any_instance.should_not_receive(:comment_pr)
Fourchette::Heroku.any_instance.should_not_receive(:fork)
expect_any_instance_of(Fourchette::GitHub).not_to receive(:comment_pr)
expect_any_instance_of(Fourchette::Heroku).not_to receive(:fork)
end
end
end

describe '#delete' do
it 'calls deletes the fork' do
Fourchette::GitHub.any_instance.stub(:comment_pr)
Fourchette::Heroku.any_instance.should_receive(:delete).with(fork_name)
allow_any_instance_of(Fourchette::GitHub).to receive(:comment_pr)
expect_any_instance_of(Fourchette::Heroku).to receive(:delete).with(fork_name)
subject.delete
end

it 'comments on the GitHub PR' do
Fourchette::Heroku.any_instance.stub(:delete)
Fourchette::GitHub.any_instance.should_receive(:comment_pr)
allow_any_instance_of(Fourchette::Heroku).to receive(:delete)
expect_any_instance_of(Fourchette::GitHub).to receive(:comment_pr)
.with(1, 'Test app deleted!')
subject.delete
end
Expand Down
38 changes: 19 additions & 19 deletions spec/lib/fourchette/github_spec.rb
Expand Up @@ -7,30 +7,30 @@

let(:fake_hook) do
hook = double('hook')
hook.stub(:config).and_return(nil)
hook.stub(:id).and_return(123)
allow(hook).to receive(:config).and_return(nil)
allow(hook).to receive(:id).and_return(123)
hook
end

let(:fake_fourchette_hook) do
fake_hook.config.stub(:fourchette_env).and_return('something')
allow(fake_hook.config).to receive(:fourchette_env).and_return('something')
fake_hook
end

let(:fake_enabled_fourchette_hook) do
fake_fourchette_hook.stub(:active).and_return(true)
allow(fake_fourchette_hook).to receive(:active).and_return(true)
fake_fourchette_hook
end

let(:fake_disabled_fourchette_hook) do
fake_fourchette_hook.stub(:active).and_return(false)
allow(fake_fourchette_hook).to receive(:active).and_return(false)
fake_fourchette_hook
end

before do
allow_message_expectations_on_nil
subject.stub(:hooks).and_return(fake_hooks)
Octokit::Client.any_instance.stub(:edit_hook)
allow(subject).to receive(:hooks).and_return(fake_hooks)
allow_any_instance_of(Octokit::Client).to receive(:edit_hook)
end

describe '#enable_hook' do
Expand All @@ -40,7 +40,7 @@
let(:fake_hooks) { [fake_enabled_fourchette_hook] }

it 'does NOT enable the hook' do
Octokit::Client.any_instance.should_not_receive(:edit_hook)
expect_any_instance_of(Octokit::Client).not_to receive(:edit_hook)

subject.enable_hook
end
Expand All @@ -50,7 +50,7 @@
let(:fake_hooks) { [fake_disabled_fourchette_hook] }

it 'enables the hook' do
Octokit::Client.any_instance.should_receive(:edit_hook)
expect_any_instance_of(Octokit::Client).to receive(:edit_hook)

subject.enable_hook
end
Expand All @@ -59,7 +59,7 @@

context 'when there is no Fourchette hook yet' do
it 'adds a hook' do
Octokit::Client.any_instance.should_receive(:create_hook)
expect_any_instance_of(Octokit::Client).to receive(:create_hook)

subject.enable_hook
end
Expand All @@ -71,7 +71,7 @@
let(:fake_hooks) { [fake_enabled_fourchette_hook] }

it 'disables the hook' do
Octokit::Client.any_instance.should_receive(:edit_hook)
expect_any_instance_of(Octokit::Client).to receive(:edit_hook)

subject.disable_hook
end
Expand All @@ -80,14 +80,14 @@
context 'when there is a disabled Fourchette hook' do
let(:fake_hooks) { [fake_disabled_fourchette_hook] }
it 'does not try to disable a hook' do
subject.should_not_receive(:disable)
expect(subject).not_to receive(:disable)
subject.disable_hook
end
end

context 'when there is no Fourchette hook' do
it 'does not try to disable a hook' do
subject.should_not_receive(:disable)
expect(subject).not_to receive(:disable)
subject.disable_hook
end
end
Expand All @@ -97,16 +97,16 @@
let(:fake_hooks) { [fake_enabled_fourchette_hook] }

it 'calls toggle_active_state_to' do
subject
.should_receive(:toggle_active_state_to)
expect(subject)
.to receive(:toggle_active_state_to)
subject.update_hook
end
end

describe '#delete_hook' do
it 'deletes the hook on GitHub' do
subject.stub(:fourchette_hook).and_return(fake_hook)
Octokit::Client.any_instance.should_receive(:remove_hook)
allow(subject).to receive(:fourchette_hook).and_return(fake_hook)
expect_any_instance_of(Octokit::Client).to receive(:remove_hook)

subject.delete_hook
end
Expand All @@ -118,8 +118,8 @@
end

it 'adds a comment' do
Octokit::Client.any_instance
.should_receive(:add_comment).with('my-project', 1, 'yo!')
expect_any_instance_of(Octokit::Client)
.to receive(:add_comment).with('my-project', 1, 'yo!')

subject.comment_pr(1, 'yo!')
end
Expand Down
67 changes: 33 additions & 34 deletions spec/lib/fourchette/heroku_spec.rb
Expand Up @@ -14,16 +14,16 @@
before do
client = double('client')
client_app = double('client')
client_app.stub(:list).and_return(app_list)
client.stub(:app).and_return(client_app)
allow(client_app).to receive(:list).and_return(app_list)
allow(client).to receive(:app).and_return(client_app)
config_var = double('config_var')
client.stub(:config_var).and_return(config_var)
allow(client).to receive(:config_var).and_return(config_var)

client.app.stub(:info).and_return(
allow(client.app).to receive(:info).and_return(
'git_url' => 'git@heroku.com/something.git'
)

heroku.stub(:client).and_return(client)
allow(heroku).to receive(:client).and_return(client)
end

describe '#app_exists?' do
Expand All @@ -34,18 +34,18 @@

describe '#fork' do
before do
heroku.stub(:create_app)
heroku.stub(:copy_config)
heroku.stub(:copy_add_ons)
heroku.stub(:copy_pg)
heroku.stub(:copy_rack_and_rails_env_again)
allow(heroku).to receive(:create_app)
allow(heroku).to receive(:copy_config)
allow(heroku).to receive(:copy_add_ons)
allow(heroku).to receive(:copy_pg)
allow(heroku).to receive(:copy_rack_and_rails_env_again)
end

%w(
create_app copy_config copy_add_ons copy_pg copy_rack_and_rails_env_again
).each do |method_name|
it "calls `#{method_name}'" do
heroku.should_receive(method_name)
expect(heroku).to receive(method_name)
heroku.fork(from_app_name, to_app_name)
end
end
Expand All @@ -59,21 +59,21 @@

describe '#delete' do
it 'calls delete on the Heroku client' do
heroku.client.app.should_receive(:delete).with(to_app_name)
expect(heroku.client.app).to receive(:delete).with(to_app_name)
heroku.delete(to_app_name)
end
end

describe '#config_vars' do
it 'calls config_var.info on the Heroku client' do
heroku.client.config_var.should_receive(:info).with(from_app_name)
expect(heroku.client.config_var).to receive(:info).with(from_app_name)
heroku.config_vars(from_app_name)
end
end

describe '#create_app' do
it 'calls app.create on the Heroku client' do
heroku.client.app.should_receive(:create).with(name: to_app_name)
expect(heroku.client.app).to receive(:create).with(name: to_app_name)
heroku.create_app(to_app_name)
end
end
Expand All @@ -89,15 +89,15 @@
let(:cleaned_vars) { { 'WHATEVER' => 'ok' } }

it 'calls #config_vars' do
heroku.client.config_var.stub(:update)
heroku.should_receive(:config_vars).with(from_app_name).and_return(vars)
allow(heroku.client.config_var).to receive(:update)
expect(heroku).to receive(:config_vars).with(from_app_name).and_return(vars)
heroku.copy_config(from_app_name, to_app_name)
end

it 'updates config vars without postgres URLs' do
heroku.client.config_var.should_receive(:update)
expect(heroku.client.config_var).to receive(:update)
.with(to_app_name, cleaned_vars)
heroku.stub(:config_vars).and_return(vars)
allow(heroku).to receive(:config_vars).and_return(vars)
heroku.copy_config('from', to_app_name)
end
end
Expand All @@ -106,19 +106,19 @@
let(:addon_list) { [{ 'plan' => { 'name' => 'redistogo' } }] }

before do
heroku.client.stub(:addon).and_return(double('addon'))
heroku.client.addon.stub(:create)
heroku.client.addon.stub(:list).and_return(addon_list)
allow(heroku.client).to receive(:addon).and_return(double('addon'))
allow(heroku.client.addon).to receive(:create)
allow(heroku.client.addon).to receive(:list).and_return(addon_list)
end

it 'gets the addon list' do
heroku.client.addon.should_receive(:list).with(from_app_name)
expect(heroku.client.addon).to receive(:list).with(from_app_name)
.and_return(addon_list)
heroku.copy_add_ons(from_app_name, to_app_name)
end

it 'creates addons' do
heroku.client.addon.should_receive(:create).with(
expect(heroku.client.addon).to receive(:create).with(
to_app_name, plan: 'redistogo'
)
heroku.copy_add_ons(from_app_name, to_app_name)
Expand All @@ -128,8 +128,8 @@
describe '#copy_pg' do

before do
heroku.client.stub(:addon).and_return(double('addon'))
heroku.client.addon.stub(:list).and_return(addon_list)
allow(heroku.client).to receive(:addon).and_return(double('addon'))
allow(heroku.client.addon).to receive(:list).and_return(addon_list)
end

context 'when a heroku-postgresql addon is enabled' do
Expand All @@ -138,7 +138,7 @@
end

it 'calls Fourchette::Pgbackups#copy' do
Fourchette::Pgbackups.any_instance.should_receive(:copy).with(
expect_any_instance_of(Fourchette::Pgbackups).to receive(:copy).with(
from_app_name, to_app_name
)
heroku.copy_pg(from_app_name, to_app_name)
Expand All @@ -153,24 +153,23 @@
# should_not_receive
# See https://github.com/rspec/rspec-mocks/issues/164 for more details
count = 0
Fourchette::Pgbackups
.any_instance.stub(:copy) do |_from_app_name, _to_app_name|
allow_any_instance_of(Fourchette::Pgbackups).to receive(:copy) do |_from_app_name, _to_app_name|
count += 1
end
heroku.copy_pg(from_app_name, to_app_name)
count.should eq(0)
expect(count).to eq(0)
end
end
end

describe '#copy_rack_and_rails_env_again' do
context 'with RACK_ENV or RAILS_ENV setup' do
before do
heroku.stub(:get_original_env).and_return('RACK_ENV' => 'qa')
allow(heroku).to receive(:get_original_env).and_return('RACK_ENV' => 'qa')
end

it 'updates the config vars' do
heroku.client.config_var.should_receive(:update).with(
expect(heroku.client.config_var).to receive(:update).with(
to_app_name, 'RACK_ENV' => 'qa'
)
heroku.copy_rack_and_rails_env_again(from_app_name, to_app_name)
Expand All @@ -179,11 +178,11 @@

context 'with NO env setup' do
before do
heroku.stub(:get_original_env).and_return({})
allow(heroku).to receive(:get_original_env).and_return({})
end

it 'does not update config vars' do
heroku.client.config_var.should_not_receive(:update)
expect(heroku.client.config_var).not_to receive(:update)
heroku.copy_rack_and_rails_env_again(from_app_name, to_app_name)
end
end
Expand All @@ -196,7 +195,7 @@
'RAILS_ENV' => 'staging',
'DATABASE_URL' => 'postgres://....'
}
heroku.stub_chain(:client, :config_var, :info).and_return(stub_cong_var)
allow(heroku).to receive_message_chain(:client, :config_var, :info).and_return(stub_cong_var)
end

it 'returns the set env vars' do
Expand Down

0 comments on commit 4b6de40

Please sign in to comment.