Permalink
Browse files

Merge pull request #1 from ileitch/ruby18

1.8 support.
  • Loading branch information...
2 parents 1b54126 + ed7b19e commit 1cdbcfc3fe6749fa1c4a56a5553afa9fae14c60b @nicksieger nicksieger committed Jan 23, 2013
View
@@ -15,6 +15,7 @@ gem "rspec-given", "~>1.0", :group => [:development, :test]
gem "simplecov", "~>0.6.0", :group => [:development, :test]
gem "em-proxy", "~>0.1.0", :group => [:development, :test]
gem "ci_reporter", "~>1.7.0", :group => [:development, :test]
+gem "activesupport", "~>3.0", :group => [:development, :test]
gem "hoe", "~>3.0", :group => [:development, :test]
# vim: syntax=ruby
View
@@ -2,6 +2,9 @@ GEM
remote: http://rubygems.org/
specs:
ZenTest (4.8.0)
+ activesupport (3.2.11)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
builder (3.1.4)
ci_reporter (1.7.3)
builder (>= 2.1.2)
@@ -17,6 +20,7 @@ GEM
hoe (>= 2.2.0)
hoe-git (1.5.0)
hoe (>= 2.2.0)
+ i18n (0.6.1)
json (1.6.6)
multi_json (1.3.6)
rake (0.9.2.2)
@@ -42,6 +46,7 @@ PLATFORMS
DEPENDENCIES
ZenTest (~> 4.8.0)
+ activesupport (~> 3.0)
ci_reporter (~> 1.7.0)
em-proxy (~> 0.1.0)
hoe (~> 3.0)
View
@@ -13,15 +13,16 @@ Hoe.spec 'klomp' do
self.clean_globs << 'spec/reports'
### dependencies!
- self.extra_dev_deps << [ 'hoe-bundler', '~> 1.1.0' ]
- self.extra_dev_deps << [ 'hoe-gemspec', '~> 1.0.0' ]
- self.extra_dev_deps << [ 'hoe-git', '~> 1.5.0' ]
- self.extra_dev_deps << [ 'rspec', '~> 2.11.0' ]
- self.extra_dev_deps << [ 'ZenTest', '~> 4.8.0' ]
- self.extra_dev_deps << [ 'rspec-given', '~> 1.0' ]
- self.extra_dev_deps << [ 'simplecov', '~> 0.6.0' ]
- self.extra_dev_deps << [ 'em-proxy', '~> 0.1.0' ]
- self.extra_dev_deps << [ 'ci_reporter', '~> 1.7.0' ]
+ self.extra_dev_deps << [ 'hoe-bundler', '~> 1.1.0' ]
+ self.extra_dev_deps << [ 'hoe-gemspec', '~> 1.0.0' ]
+ self.extra_dev_deps << [ 'hoe-git', '~> 1.5.0' ]
+ self.extra_dev_deps << [ 'rspec', '~> 2.11.0' ]
+ self.extra_dev_deps << [ 'ZenTest', '~> 4.8.0' ]
+ self.extra_dev_deps << [ 'rspec-given', '~> 1.0' ]
+ self.extra_dev_deps << [ 'simplecov', '~> 0.6.0' ]
+ self.extra_dev_deps << [ 'em-proxy', '~> 0.1.0' ]
+ self.extra_dev_deps << [ 'ci_reporter', '~> 1.7.0' ]
+ self.extra_dev_deps << [ 'activesupport', '~> 3.0' ]
end
require 'ci/reporter/rake/rspec'
View
@@ -14,7 +14,7 @@ def initialize(servers, options = {})
def publish(queue, body, headers = {})
connections_remaining = connections.dup
begin
- conn = connections_remaining.sample
+ conn = connections_remaining[rand(connections_remaining.size)]
conn.publish(queue, body, headers)
rescue
connections_remaining.delete conn
@@ -84,7 +84,7 @@ def reconnect
private
def connect
@socket = TCPSocket.new *options['server']
- @socket.set_encoding 'UTF-8'
+ @socket.set_encoding 'UTF-8' if @socket.respond_to?(:set_encoding)
write Frames::Connect.new(options)
frame = read Frames::Connected, @select_timeout
log_frame frame if logger
View
@@ -5,9 +5,14 @@ module Frames
class Frame
def name; @name ||= self.class.name.split('::').last.upcase; end
- def headers; @headers ||= {}; end
- def [](key); headers[key]; end
- def []=(key, value); headers[key] = value; end
+ def new_headers
+ # Dependency injection point for tests.
+ {}
+ end
+
+ def headers; @headers ||= new_headers; end
+ def [](key); headers[key]; end
+ def []=(key, value); headers[key] = value; end
def body; @body ||= ""; end
def body=(b); @body = b; end
@@ -44,7 +49,7 @@ def parse(data)
def parse_headers(data)
frame = nil
- {}.tap do |headers|
+ new_headers.tap do |headers|
data.lines.each do |line|
next if line == "\n"
unless frame
@@ -16,7 +16,7 @@
context "publish" do
- When { klomp.publish "/queue/greeting", "hello" }
+ When { klomp.publish("/queue/greeting", "hello") }
Then do
vhosts = apollo_api_get_json "/broker/virtual-hosts.json"
@@ -4,18 +4,24 @@
Given(:data) { frame(:connected) }
Given(:server) { "127.0.0.1:61613" }
- Given(:options) { { "login" => "admin", "passcode" => "password", "logger" => logger } }
- Given(:socket) { double(TCPSocket, gets:data, write:nil, set_encoding:nil, close:nil) }
- Given(:logger) { double("Logger", error:nil, warn:nil, info:nil, debug:nil).as_null_object }
- Given(:subscriber) { double "subscriber", call:nil }
+ Given(:socket) { double(TCPSocket, :gets => data, :write => nil, :set_encoding => nil, :close => nil) }
+ Given(:logger) { double("Logger", :error => nil, :warn => nil, :info => nil, :debug => nil).as_null_object }
+ Given(:subscriber) { double "subscriber", :call => nil }
Given(:thread) { double Thread }
- Given(:sentinel) { double Klomp::Sentinel, alive?:true }
+ Given(:sentinel) { double Klomp::Sentinel, :alive? => true }
+ Given(:options) {
+ hsh = ActiveSupport::OrderedHash.new
+ hsh['login'] = 'admin'
+ hsh['passcode'] = 'password'
+ hsh['logger'] = logger
+ hsh
+ }
Given do
IO.stub!(:select).and_return([[socket], [socket]])
TCPSocket.stub!(:new).and_return socket
Thread.stub!(:new).and_return {|*args,&blk| thread.stub!(:block => blk); thread }
- Klomp::Sentinel.stub!(new: sentinel)
+ Klomp::Sentinel.stub!(:new => sentinel)
end
context "new" do
@@ -78,7 +84,7 @@
context "logs when logger level is debug" do
- Given(:logger) { double("Logger").as_null_object.tap {|l| l.stub!(debug?: true) } }
+ Given(:logger) { double("Logger").as_null_object.tap {|l| l.stub!(:debug? => true) } }
Then { logger.should have_received(:debug) }
@@ -100,7 +106,7 @@
context "and logs when logger level is debug" do
- Given(:logger) { double("Logger").as_null_object.tap {|l| l.stub!(debug?: true) } }
+ Given(:logger) { double("Logger").as_null_object.tap {|l| l.stub!(:debug? => true) } }
Then { logger.should have_received(:debug) }
@@ -112,7 +118,7 @@
When do
connection.subscribe "/queue/greeting", subscriber
- connection.subscribe "/queue/greeting", double("another subscriber that replaces the first", call:nil)
+ connection.subscribe "/queue/greeting", double("another subscriber that replaces the first", :call => nil)
end
Then { socket.should have_received(:write).with(frame(:subscribe)).once }
@@ -225,7 +231,7 @@
context "disconnect" do
- Given!(:connection) { Klomp::Connection.new server, options }
+ Given!(:connection) { Klomp::Connection.new server, options}
When(:result) { connection.disconnect }
@@ -293,7 +299,7 @@
Given!(:connection) { Klomp::Connection.new server, options }
Given do
- thread.stub!(:raise).and_return {|e| raise e }
+ thread.stub!(:raise).and_return {|e, _| raise e }
socket.stub!(:gets).and_raise SystemCallError.new("some socket error")
end
@@ -22,7 +22,7 @@
context "stringifies all header keys and values" do
- Given(:headers) { { timeout:42 } }
+ Given(:headers) { { :timeout => 42 } }
When(:send_frame) { Klomp::Frames::Send.new("/queue/q", "", headers) }
@@ -2,7 +2,7 @@
describe Klomp::Sentinel do
- Given(:connection) { double "Connection", connected?:false, reconnect:nil }
+ Given(:connection) { double "Connection", :connected? => false, :reconnect => nil }
Given(:sentinel) { Klomp::Sentinel.new connection }
Given(:thread) { double Thread }
Given do
@@ -11,7 +11,7 @@
context "does nothing if the connection is already connected" do
- Given { connection.stub!(connected?: true) }
+ Given { connection.stub!(:connected? => true) }
When { sentinel }
View
@@ -4,7 +4,7 @@
Given(:servers) { ["127.0.0.1:61613", "127.0.0.1:67673"] }
Given(:connections) { Hash[*servers.map {|s| [s, double("connection #{s}")] }.flatten] }
- Given { Klomp::Connection.stub!(:new).and_return {|s| connections[s] } }
+ Given { Klomp::Connection.stub!(:new).and_return {|s, _| connections[s] } }
Given(:klomp) { Klomp.new servers }
context "new" do
@@ -113,7 +113,7 @@
context "calls subscribe on all of the servers" do
- Given { connections.values.each {|conn| conn.stub!(subscribe: 42) } }
+ Given { connections.values.each {|conn| conn.stub!(:subscribe => 42) } }
When(:result) { klomp.subscribe("/queue/greeting") { true } }
@@ -143,7 +143,7 @@
context "calls unsubscribe on all the servers" do
- Given { connections.values.each {|conn| conn.stub!(unsubscribe: 42) } }
+ Given { connections.values.each {|conn| conn.stub!(:unsubscribe => 42) } }
When(:result) { klomp.unsubscribe("/queue/greeting") }
@@ -197,7 +197,7 @@
context "disconnects all the servers" do
- Given { connections.values.each {|conn| conn.stub!(disconnect: 42) } }
+ Given { connections.values.each {|conn| conn.stub!(:disconnect => 42) } }
When(:result) { klomp.disconnect }
View
@@ -1,7 +1,8 @@
-require 'simplecov'
+require 'simplecov' if RUBY_VERSION >= '1.9'
require 'klomp'
require 'rspec'
require 'rspec-given'
+require 'active_support'
Dir[File.expand_path('../support/', __FILE__) + '/*.rb'].each {|f| require f }
@@ -32,5 +33,11 @@ def queue_available?
config.filter_run_excluding :performance
end
+ config.before :each do
+ Klomp::Frames::Frame.any_instance.stub(:new_headers) do
+ ActiveSupport::OrderedHash.new
+ end
+ end
+
config.include Frames
end
@@ -54,7 +54,7 @@ class Matcher
def initialize(message, expected_from)
@message, @mock = message, RSpec::Mocks::Mock.new
@mock.stub!(message)
- @expectation = @mock.should_receive(message, expected_from: expected_from)
+ @expectation = @mock.should_receive(message, expected_from => expected_from)
end
def matches?(actual)

0 comments on commit 1cdbcfc

Please sign in to comment.