Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix specs for ruby 1.9.1

  • Loading branch information...
commit cc34e6e44514447717c7d8cc70446fb6e6f08d47 1 parent 8990938
Dan DeLeo authored
6 lib/qusion/amqp.rb
View
@@ -10,11 +10,11 @@ def self.start_web_dispatcher(amqp_settings={})
EM.kill_reactor
Thread.current[:mq], @conn = nil, nil
end
- Thread.new { self.start }
+ Thread.new { start }
die_gracefully_on_signal
end
when :standard
- Thread.new { self.start }
+ Thread.new { start }
die_gracefully_on_signal
when :evented
die_gracefully_on_signal
@@ -25,7 +25,7 @@ def self.start_web_dispatcher(amqp_settings={})
end
def self.die_gracefully_on_signal
- Signal.trap("INT") { AMQP.stop { EM.stop } }
+ Signal.trap("INT") { AMQP.stop { EM.stop } }
Signal.trap("TERM") { AMQP.stop { EM.stop } }
end
end
1  lib/qusion/amqp_config.rb
View
@@ -1,4 +1,5 @@
# encoding: UTF-8
+require 'yaml'
module Qusion
5 spec/spec_helper.rb
View
@@ -1,5 +1,8 @@
# encoding: UTF-8
-require 'rubygems'
+begin
+ require 'rubygems'
+rescue LoadError
+end
require File.dirname(__FILE__) + '/../lib/qusion.rb'
24 spec/unit/amqp_config_spec.rb
View
@@ -4,40 +4,40 @@
describe AmqpConfig do
after(:each) do
- Object.send(:remove_const, :RAILS_ROOT) if defined? RAILS_ROOT
- Object.send(:remove_const, :Merb) if defined? Merb
+ Object.send(:remove_const, :RAILS_ROOT) if defined? ::RAILS_ROOT
+ Object.send(:remove_const, :Merb) if defined? ::Merb
end
it "should use RAILS_ROOT/config/amqp.yml if RAILS_ROOT is defined" do
- RAILS_ROOT = "/path/to/rails"
- RAILS_ENV = nil
+ ::RAILS_ROOT = "/path/to/rails"
+ ::RAILS_ENV = nil
AmqpConfig.new.config_path.should == "/path/to/rails/config/amqp.yml"
end
it "should use \#{Merb.root}/config/amqp.yml if RAILS_ROOT is undefined and Merb is defined" do
- Merb = mock("merby")
- Merb.should_receive(:root).and_return("/path/to/merb")
- Merb.should_receive(:environment).and_return(nil)
+ ::Merb = mock("merby")
+ ::Merb.should_receive(:root).and_return("/path/to/merb")
+ ::Merb.should_receive(:environment).and_return(nil)
AmqpConfig.new.config_path.should == "/path/to/merb/config/amqp.yml"
end
it "should use the provided path no matter what" do
- RAILS_ROOT = nil
- Merb = nil
+ ::RAILS_ROOT = nil
+ ::Merb = nil
path = AmqpConfig.new("/custom/path/to/amqp.yml").config_path
path.should == "/custom/path/to/amqp.yml"
end
it "should use a provided options hash if given" do
- RAILS_ROOT = nil
- Merb = nil
+ ::RAILS_ROOT = nil
+ ::Merb = nil
conf = AmqpConfig.new(:host => "my-broker.mydomain.com")
conf.config_path.should be_nil
conf.config_opts.should == {:host => "my-broker.mydomain.com"}
end
it "should use the default amqp options in rails if amqp.yml doesn't exist" do
- RAILS_ROOT = File.dirname(__FILE__) + '/../'
+ ::RAILS_ROOT = File.dirname(__FILE__) + '/../'
AmqpConfig.new.config_opts.should == {}
end
16 spec/unit/amqp_spec.rb
View
@@ -8,33 +8,35 @@
end
after(:each) do
- Object.send(:remove_const, :PhusionPassenger) if defined? PhusionPassenger
- Object.send(:remove_const, :Thin) if defined? Thin
- Object.send(:remove_const, :Mongrel) if defined? Mongrel
+ Object.send(:remove_const, :PhusionPassenger) if defined? ::PhusionPassenger
+ Object.send(:remove_const, :Thin) if defined? ::Thin
+ Object.send(:remove_const, :Mongrel) if defined? ::Mongrel
end
it "should kill the reactor and start a new AMQP connection when forked in Passenger" do
AMQP.should_receive(:die_gracefully_on_signal)
- PhusionPassenger = Object.new
+ ::PhusionPassenger = Module.new
forked = mock("starting_worker_process_callback_obj")
- PhusionPassenger.should_receive(:on_event).with(:starting_worker_process).and_yield(forked)
+ ::PhusionPassenger.should_receive(:on_event).with(:starting_worker_process).and_yield(forked)
EM.should_receive(:kill_reactor)
AMQP.should_receive(:start)
AMQP.start_web_dispatcher
+ sleep 0.1 # give the thread time to run, esp. on ruby 1.9
end
it "should set AMQP's connection settings when running under Thin" do
AMQP.should_receive(:die_gracefully_on_signal)
- Thin = Object.new
+ ::Thin = Module.new
AMQP.start_web_dispatcher({:cookie => "yummy"})
AMQP.instance_variable_get(:@settings)[:cookie].should == "yummy"
end
it "should start a worker thread when running under Mongrel" do
AMQP.should_receive(:die_gracefully_on_signal)
- Mongrel = Object.new
+ ::Mongrel = Module.new
AMQP.should_receive(:start)
AMQP.start_web_dispatcher
+ sleep 0.1 # give the thread time to run, esp. on ruby 1.9
end
end
4 spec/unit/channel_pool_spec.rb
View
@@ -25,12 +25,12 @@
it "should create a pool of AMQP channels" do
ChannelPool.pool_size = 3
- MQ.should_receive(:new).exactly(3).times
+ ::MQ.should_receive(:new).exactly(3).times
@channel_pool.pool
end
it "should default to a pool size of 5" do
- MQ.should_receive(:new).exactly(5).times.and_return("swanky")
+ ::MQ.should_receive(:new).exactly(5).times.and_return("swanky")
@channel_pool.pool
@channel_pool.instance_variable_get(:@pool).should == %w{ swanky swanky swanky swanky swanky}
end
34 spec/unit/server_spy_spec.rb
View
@@ -4,55 +4,55 @@
describe ServerSpy do
after do
- Object.send(:remove_const, :SCGI) if defined? SCGI
- Object.send(:remove_const, :WEBrick) if defined? WEBrick
- Object.send(:remove_const, :PhusionPassenger) if defined? PhusionPassenger
- Object.send(:remove_const, :Thin) if defined? Thin
- Mongrel.send(:remove_const, :MongrelProtocol) if defined?(Mongrel::MongrelProtocol)
- Object.send(:remove_const, :Mongrel) if defined? Mongrel
+ Object.send(:remove_const, :SCGI) if defined? ::SCGI
+ Object.send(:remove_const, :WEBrick) if defined? ::WEBrick
+ Object.send(:remove_const, :PhusionPassenger) if defined? ::PhusionPassenger
+ Object.send(:remove_const, :Thin) if defined? ::Thin
+ Mongrel.send(:remove_const, :MongrelProtocol) if defined?(::Mongrel::MongrelProtocol)
+ Object.send(:remove_const, :Mongrel) if defined? ::Mongrel
end
it "maps evented mongrel to :evented" do
- Mongrel = Module.new
- Mongrel::MongrelProtocol = Object.new
+ ::Mongrel = Module.new
+ ::Mongrel::MongrelProtocol = Module.new
ServerSpy.server_type.should == :evented
end
it "maps Mongrel to :standard" do
- Mongrel = Object.new
+ ::Mongrel = Module.new
ServerSpy.server_type.should == :standard
end
it "maps WEBrick to :standard" do
- WEBrick = Object.new
+ ::WEBrick = Module.new
ServerSpy.server_type.should == :standard
end
it "maps SCGI to :standard" do
- SCGI = Object.new
+ ::SCGI = Module.new
ServerSpy.server_type.should == :standard
end
it "maps PhusionPassenger to :passenger" do
- PhusionPassenger = Object.new
+ ::PhusionPassenger = Module.new
ServerSpy.server_type.should == :passenger
end
it "maps Thin to :evented" do
- Thin = Object.new
+ ::Thin = Module.new
ServerSpy.server_type.should == :evented
end
# Rails after 2.2(?) to edge circa Aug 2009 loads thin if it's installed no matter what
it "gives the server type as :standard if both Thin and Mongrel are defined" do
- Mongrel = Object.new
- Thin = Object.new
+ ::Mongrel = Module.new
+ ::Thin = Module.new
ServerSpy.server_type.should == :standard
end
it "gives the server type as :passenger if both Thin and PhusionPassenger" do
- PhusionPassenger = Object.new
- Thin = Object.new
+ ::PhusionPassenger = Module.new
+ ::Thin = Module.new
ServerSpy.server_type.should == :passenger
end
Please sign in to comment.
Something went wrong with that request. Please try again.