spec/spec_helper.rb in amqp-0.7.5 vs spec/spec_helper.rb in amqp-0.8.0.beta1
- old
+ new
@@ -7,10 +7,76 @@
Bundler.require :default, :test
require "amqp"
require "evented-spec"
+# See https://gist.github.com/892414
+RSpec::Core::Example.send(:include, Module.new {
+ def self.included(base)
+ base.class_eval do
+ alias_method :__finish__, :finish
+ remove_method :finish
+ end
+ end
+
+ attr_reader :not_implemented_error
+ def from_not_implemented_error?
+ !! @not_implemented_error
+ end
+
+ def finish(reporter)
+ if @exception.is_a?(NotImplementedError)
+ @not_implemented_error = @exception
+ message = "#{@exception.message} (from #{@exception.backtrace[0]})"
+ self.metadata[:pending] = true
+ @pending_declared_in_example = message
+ @exception = nil
+ end
+
+ __finish__(reporter)
+ end
+})
+
+RSpec::Core::Formatters::BaseTextFormatter.send(:include, Module.new {
+ def self.included(base)
+ base.class_eval do
+ remove_method :dump_pending
+ remove_method :dump_backtrace
+ end
+ end
+
+ def dump_pending
+ unless pending_examples.empty?
+ output.puts
+ output.puts "Pending:"
+ pending_examples.each do |pending_example|
+ output.puts yellow(" #{pending_example.full_description}")
+ output.puts grey(" # #{pending_example.execution_result[:pending_message]}")
+ output.puts grey(" # #{format_caller(pending_example.location)}")
+ if pending_example.from_not_implemented_error? && RSpec.configuration.backtrace_clean_patterns.empty?
+ dump_backtrace(pending_example, pending_example.not_implemented_error.backtrace)
+ end
+ end
+ end
+ end
+
+ def dump_backtrace(example, backtrace = example.execution_result[:exception].backtrace)
+ format_backtrace(backtrace, example).each do |backtrace_info|
+ output.puts grey("#{long_padding}# #{backtrace_info}")
+ end
+ end
+})
+
+def em_amqp_connect(&block)
+ em do
+ AMQ::Client::EventMachineClient.connect(:port => 5672, :vhost => "/amq_client_testbed", :frame_max => 65536, :heartbeat_interval => 1) do |client|
+ yield client
+ end
+ end
+end
+
+
amqp_config = File.dirname(__FILE__) + '/amqp.yml'
if File.exists? amqp_config
class Hash
def symbolize_keys
@@ -22,64 +88,24 @@
end
end
end
AMQP_OPTS = YAML::load_file(amqp_config).symbolize_keys[:test]
else
- AMQP_OPTS = {:host => 'localhost', :port => 5672, :username => "guest", :password => "guest", :vhost => "/"}
+ AMQP_OPTS = {:host => 'localhost', :port => 5672}
end
+
#
# Ruby version-specific
#
case RUBY_VERSION
when "1.8.7" then
- module ArrayExtensions
- def sample
- self.choice
- end # sample
- end
-
class Array
- include ArrayExtensions
+ alias sample choice
end
when "1.8.6" then
raise "Ruby 1.8.6 is not supported. Sorry, pal. Time to move on beyond One True Ruby. Yes, time flies by."
when /^1.9/ then
- puts "Encoding.default_internal was #{Encoding.default_internal || 'not set'}, switching to #{Encoding::UTF_8}"
Encoding.default_internal = Encoding::UTF_8
-
- puts "Encoding.default_external was #{Encoding.default_internal || 'not set'}, switching to #{Encoding::UTF_8}"
Encoding.default_external = Encoding::UTF_8
end
-
-
-# Returns Header that should be correctly parsed
-def basic_header(opts = {})
- AMQP::Frame::Header.new(
- AMQP::Protocol::Header.new(
- AMQP::Protocol::Basic, :priority => 1), opts[:channel] || 0)
-end
-
-# Returns AMQP Frame::Header frame that contains Protocol::Header header
-# with (pre-)defined accessors set.
-def test_header opts = {}
- AMQP::Frame::Header.new(
- AMQP::Protocol::Header.new(
- opts[:klass] || AMQP::Protocol::Test,
- opts[:size] || 4,
- opts[:weight] || 2,
- opts[:properties] || {:delivery_mode => 1}))
-end
-
-# Returns AMQP Frame::Method frame that contains Protocol::Basic::Deliver
-# with (pre-)defined accessors set.
-def test_method_deliver opts = {}
- AMQP::Frame::Method.new(
- AMQP::Protocol::Basic::Deliver.new(
- :consumer_tag => opts[:consumer_tag] || 'test_consumer'))
-end
-
-def delayed(timeout, &block)
- instance = self
- EM.add_timer(timeout) { instance.instance_eval(&block) }
-end # delayed