Permalink
Browse files

Rewrote configuration

  • Loading branch information...
txus committed Nov 28, 2010
1 parent 5787d6f commit 3def1e4ee6a89d04668618407a4491a8733eff77
Showing with 33 additions and 6 deletions.
  1. +1 −0 lib/hijacker.rb
  2. +2 −2 lib/hijacker/config.rb
  3. +3 −0 lib/hijacker/exceptions.rb
  4. +27 −4 spec/hijacker/config_spec.rb
View
@@ -1,5 +1,6 @@
require 'drb'
require 'trollop'
+require 'hijacker/exceptions'
require 'hijacker/config'
require 'hijacker/handler'
View
@@ -11,8 +11,8 @@ def uri(drb)
def drb_uri
begin
@@drb_uri
- rescue
- raise "Neither a global nor a local Hijacker server URI is configured. Please refer to the README to find out how to do this."
+ rescue NameError
+ raise UndefinedUriError, "Neither a global nor a local Hijacker server URI is configured. Please refer to the README to find out how to do this."
end
end
end
@@ -0,0 +1,3 @@
+module Hijacker
+ class UndefinedUriError < StandardError; end;
+end
@@ -3,11 +3,34 @@
describe Hijacker, "configuration" do
describe "#configure" do
- it 'accepts a block with the \'uri\' configuration option' do
- Hijacker.configure do
- uri 'druby://localhost:8787'
+ it 'evaluates the passed block' do
+ block = Proc.new {}
+ Hijacker.should_receive(:instance_eval).with(&block).once
+ Hijacker.configure(&block)
+ end
+ end
+
+ describe "#uri" do
+ it 'assigns the DRb uri as a class variable' do
+ Hijacker.uri 'druby://localhost:8787'
+ Hijacker.class_variable_get(:@@drb_uri).should == 'druby://localhost:8787'
+ end
+ end
+
+ describe "#drb_uri" do
+ context "when the class variable is set" do
+ it 'is an accessor to it' do
+ Hijacker.class_variable_set(:@@drb_uri, 'druby://localhost:8787')
+ Hijacker.drb_uri.should == 'druby://localhost:8787'
+ end
+ end
+ context "otherwise" do
+ it 'raises an error' do
+ Hijacker.remove_class_variable(:@@drb_uri)
+ expect {
+ Hijacker.drb_uri
+ }.to raise_error(Hijacker::UndefinedUriError)
end
- Hijacker.drb_uri.should == 'druby://localhost:8787'
end
end

0 comments on commit 3def1e4

Please sign in to comment.