Permalink
Browse files

Validate configuration options

  • Loading branch information...
1 parent 7c55f58 commit ee860ac2c955cf7182c203b6ad071abb9d6cd8f5 @iain committed Apr 5, 2012
Showing with 29 additions and 1 deletion.
  1. +22 −1 lib/capistrano/blaze.rb
  2. +7 −0 spec/camp_spec.rb
View
@@ -14,14 +14,15 @@ module Blaze
def_delegators :Messages, :start, :failure, :success, :test
def configure
- yield configuration if block_given?
+ yield configuration
end
def configuration
@config ||= OpenStruct.new
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
@@ -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.