Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Validate configuration options

  • Loading branch information...
commit ee860ac2c955cf7182c203b6ad071abb9d6cd8f5 1 parent 7c55f58
@iain authored
Showing with 29 additions and 1 deletion.
  1. +22 −1 lib/capistrano/blaze.rb
  2. +7 −0 spec/camp_spec.rb
View
23 lib/capistrano/blaze.rb
@@ -14,7 +14,7 @@ module Blaze
def_delegators :Messages, :start, :failure, :success, :test
def configure
- yield configuration if block_given?
+ yield configuration
end
def configuration
@@ -22,6 +22,7 @@ def configuration
end
def speak(message)
+ validate_configuration
port = configuration.ssl ? 443 : 80
req = Net::HTTP::Post.new("/room/#{configuration.room_id}/speak.json")
@@ -43,5 +44,25 @@ def speak(message)
end
end
+ def validate_configuration
+ %w(account room_id token).each do |option|
+ if configuration.send(option).nil?
+ fail MissingConfigurationOption.new(option)
+ end
+ end
+ end
+
+ class MissingConfigurationOption < RuntimeError
+
+ def initialize(option)
+ @option = option
+ end
+
+ def to_s
+ "Please specify the #{@option} option"
+ end
+
+ end
+
end
end
View
7 spec/camp_spec.rb
@@ -34,6 +34,13 @@
subject.speak "Ik ben een gem aan het maken"
end
+ it "validates configuration" do
+ subject.configure do |config|
+ config.account = nil
+ end
+ expect { subject.speak "something" }.to raise_error("Please specify the account option")
+ end
+
it "displays a start message" do
subject.should_receive(:speak).with("your mom is deploying to the production stage of basecamp, via `#{command}`")
context = stub(:stage => "production", :application => "basecamp")

0 comments on commit ee860ac

Please sign in to comment.
Something went wrong with that request. Please try again.