Skip to content

Commit

Permalink
Rewrote configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Dec 5, 2010
1 parent 5787d6f commit 3def1e4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/hijacker.rb
@@ -1,5 +1,6 @@
require 'drb'
require 'trollop'
require 'hijacker/exceptions'
require 'hijacker/config'
require 'hijacker/handler'

Expand Down
4 changes: 2 additions & 2 deletions lib/hijacker/config.rb
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/hijacker/exceptions.rb
@@ -0,0 +1,3 @@
module Hijacker
class UndefinedUriError < StandardError; end;
end
31 changes: 27 additions & 4 deletions spec/hijacker/config_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 3def1e4

Please sign in to comment.