Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Specs #4

Merged
merged 4 commits into from

2 participants

@linedotstar

@jcwilk can you take a look at the specs? it's a little awkward spec'ing capistrano tasks. any ideas on how to make these cleaner would be appreciated.

Chris Friedrich and others added some commits
@jcwilk jcwilk commented on the diff
spec/campystrano_spec.rb
@@ -0,0 +1,107 @@
+require 'spec_helper'
+
+# include #_cset since it's not automatically included in Capistrano::Configuration
@jcwilk
jcwilk added a note

is there no way to require some file or something like that so that the definition comes from capistrano code rather than duplicating it here?

Unfortunately, they define this method in the deploy recipe: https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy.rb#L8
which includes a lot of other code that I didn't want to introduce into the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
spec/campystrano_spec.rb
((27 lines not shown))
+ c.set(:application) { application }
+ c.set(:rails_env) { rails_env }
+ c.set(:branch) { branch }
+ c.set(:campfire_emoji) { campfire_emoji }
+ c.set(:campfire_settings) { campfire_settings }
+
+ Tinder::Campfire.stub(:new).and_return(campfire)
+ c.stub(:`).with('whoami').and_return(user)
+
+ Capistrano::Campystrano.load_into(c)
+ end
+ end
+
+ subject { config.find_and_execute_task(task) }
+
+ shared_examples_for 'a campystrano deploy task' do |message|
@jcwilk
jcwilk added a note

is |message| supposed to be here? looks like it's not used

gc. fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jcwilk jcwilk commented on the diff
spec/campystrano_spec.rb
@@ -0,0 +1,107 @@
+require 'spec_helper'
+
+# include #_cset since it's not automatically included in Capistrano::Configuration
+class Capistrano::Configuration
+ def _cset(name, *args, &block)
+ unless exists?(name)
+ set(name, *args, &block)
+ end
+ end
+end
+
+describe Capistrano::Campystrano do
@jcwilk
jcwilk added a note

Also, does this have to be under the Capistrano namespace? I'm not really familiar with standards around external deploy task definitions and such, but seems like it ought to just be Campystrano in the absence of a conflicting standard.

it probably doesn't. but i'd rather tackle that as part of a separate PR

@jcwilk
jcwilk added a note

sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jcwilk

Looks reasonable. Seems like you're adequately locking down the behavior defined in the code and it's pretty legible. Nice work :shipit:

Chris Friedrich version bump 7b91864
@linedotstar linedotstar merged commit 16c073c into master
@linedotstar linedotstar deleted the specs branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
  1. Add specs for the campfire deploy tasks

    Chris Friedrich authored
  2. @linedotstar

    Spec refactoring

    linedotstar authored
  3. @linedotstar
  4. version bump

    Chris Friedrich authored
This page is out of date. Refresh to see the latest.
View
10 Gemfile
@@ -6,6 +6,7 @@ source "http://rubygems.org"
gemspec
# jquery-rails is used by the dummy application
+gem 'sqlite3'
gem "jquery-rails"
# Declare any dependencies that are still in development here instead of in
@@ -13,5 +14,10 @@ gem "jquery-rails"
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
-# To use debugger
-# gem 'debugger'
+group :development, :test do
+ gem 'pry'
+ gem 'pry-nav'
+ gem 'pry-rescue'
+ gem 'pry-stack_explorer'
+ gem 'ruby-debug19'
+end
View
40 Gemfile.lock
@@ -35,7 +35,10 @@ GEM
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
+ archive-tar-minitar (0.5.2)
arel (3.0.2)
+ binding_of_caller (0.7.1)
+ debug_inspector (>= 0.0.1)
builder (3.0.4)
capistrano (2.14.2)
highline
@@ -43,6 +46,10 @@ GEM
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
+ capistrano-spec (0.2.2)
+ coderay (1.0.9)
+ columnize (0.3.6)
+ debug_inspector (0.0.2)
diff-lcs (1.1.3)
erubis (2.7.0)
eventmachine (1.0.0)
@@ -55,15 +62,19 @@ GEM
hike (1.2.1)
http_parser.rb (0.5.3)
i18n (0.6.1)
+ interception (0.3)
journey (1.0.4)
jquery-rails (2.2.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.7)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ method_source (0.8.1)
mime-types (1.21)
multi_json (1.6.1)
multipart-post (1.2.0)
@@ -75,6 +86,18 @@ GEM
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
polyglot (0.3.3)
+ pry (0.9.12)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.4)
+ pry-nav (0.2.3)
+ pry (~> 0.9.10)
+ pry-rescue (1.0.0)
+ interception (>= 0.3)
+ pry
+ pry-stack_explorer (0.4.9)
+ binding_of_caller (>= 0.7)
+ pry (~> 0.9.11)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
@@ -111,7 +134,18 @@ GEM
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
simple_oauth (0.1.9)
+ slop (3.4.4)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
@@ -143,7 +177,13 @@ PLATFORMS
DEPENDENCIES
campystrano!
+ capistrano-spec
jquery-rails
+ pry
+ pry-nav
+ pry-rescue
+ pry-stack_explorer
rails (~> 3.2.12)
rspec-rails
+ ruby-debug19
sqlite3
View
6 campystrano.gemspec
@@ -20,4 +20,10 @@ Gem::Specification.new do |s|
s.add_development_dependency "rails", "~> 3.2.12"
s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails"
+ s.add_development_dependency "capistrano-spec"
+ s.add_development_dependency 'pry'
+ s.add_development_dependency 'pry-nav'
+ s.add_development_dependency 'pry-rescue'
+ s.add_development_dependency 'pry-stack_explorer'
+ s.add_development_dependency 'ruby-debug19'
end
View
2  lib/campystrano/version.rb
@@ -1,3 +1,3 @@
module Campystrano
- VERSION = "0.0.1"
+ VERSION = "0.0.2"
end
View
107 spec/campystrano_spec.rb
@@ -0,0 +1,107 @@
+require 'spec_helper'
+
+# include #_cset since it's not automatically included in Capistrano::Configuration
@jcwilk
jcwilk added a note

is there no way to require some file or something like that so that the definition comes from capistrano code rather than duplicating it here?

Unfortunately, they define this method in the deploy recipe: https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy.rb#L8
which includes a lot of other code that I didn't want to introduce into the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+class Capistrano::Configuration
+ def _cset(name, *args, &block)
+ unless exists?(name)
+ set(name, *args, &block)
+ end
+ end
+end
+
+describe Capistrano::Campystrano do
@jcwilk
jcwilk added a note

Also, does this have to be under the Capistrano namespace? I'm not really familiar with standards around external deploy task definitions and such, but seems like it ought to just be Campystrano in the absence of a conflicting standard.

it probably doesn't. but i'd rather tackle that as part of a separate PR

@jcwilk
jcwilk added a note

sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ let(:user) { 'glen_morangie' }
+ let(:application) { 'my_app' }
+ let(:rails_env) { Rails.env.to_s }
+ let(:branch) { 'my_branch' }
+ let(:campfire_emoji) { ':neckbeard:' }
+ let(:subdomain) { 'mySubdomain' }
+ let(:room_name) { 'RedRoom' }
+ let(:token) { 'myT0k3n' }
+ let(:campfire_settings) { { subdomain: subdomain, room: room_name, token: token } }
+ let(:room) { mock('room', speak: 'spoken') }
+ let(:campfire) { mock('campfire', find_room_by_name: room) }
+
+ let!(:config) do
+ Capistrano::Configuration.new.tap do |c|
+ c.set(:application) { application }
+ c.set(:rails_env) { rails_env }
+ c.set(:branch) { branch }
+ c.set(:campfire_emoji) { campfire_emoji }
+ c.set(:campfire_settings) { campfire_settings }
+
+ Tinder::Campfire.stub(:new).and_return(campfire)
+ c.stub(:`).with('whoami').and_return(user)
+
+ Capistrano::Campystrano.load_into(c)
+ end
+ end
+
+ subject { config.find_and_execute_task(task) }
+
+ shared_examples_for 'a campystrano deploy task' do
+ context 'configuration' do
+ it 'defines the application' do
+ subject
+ config.fetch(:campy_application).should == application
+ end
+
+ it 'defines the app env' do
+ subject
+ config.fetch(:campy_app_env).should == rails_env
+ end
+
+ it 'defines the user' do
+ subject
+ config.fetch(:campy_user).should == user
+ end
+
+ it 'defines the branch' do
+ subject
+ config.fetch(:campy_branch).should == branch
+ end
+
+ it 'defines the emoji' do
+ subject
+ config.fetch(:campfire_emoji).should == campfire_emoji
+ end
+
+ it 'creates a Campfire connection' do
+ Tinder::Campfire.should_receive(:new).with(subdomain, token: token).and_return(campfire)
+ subject
+ end
+ end
+ end
+
+ describe 'deploy:campystrano:start task' do
+ let(:task) { 'deploy:campystrano:start' }
+
+ it_behaves_like 'a campystrano deploy task'
+
+ it 'sends a message to Campfire' do
+ msg = "#{user} deploying #{branch} to #{application} #{rails_env}"
+ room.should_receive(:speak).with("#{campfire_emoji}#{msg}#{campfire_emoji}")
+ subject
+ end
+
+ it 'adds itself to the before deploy callback queue' do
+ config.callbacks[:before].detect{ |cb| cb.is_a?(Capistrano::TaskCallback) }.source.should == task
+ end
+ end
+
+ describe 'deploy:campystrano:success task' do
+ let(:task) { 'deploy:campystrano:success' }
+
+ it_behaves_like 'a campystrano deploy task'
+
+ it 'sends a message to Campfire' do
+ msg = "Deploy to #{application} #{rails_env} finished successfully"
+ room.should_receive(:speak).with("#{campfire_emoji}#{msg}#{campfire_emoji}")
+ subject
+ end
+
+ it 'adds itself to the after deploy callback queue' do
+ config.callbacks[:after].detect{ |cb| cb.is_a?(Capistrano::TaskCallback) }.source.should == task
+ end
+ end
+end
View
4 spec/spec_helper.rb
@@ -3,6 +3,10 @@
require File.expand_path("../dummy/config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
+require 'pry'
+require 'pry-nav'
+require 'pry-rescue'
+require 'pry-stack_explorer'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Something went wrong with that request. Please try again.