spec/spec_helper.rb in amqp-0.7.0 vs spec/spec_helper.rb in amqp-0.7.1

- old
+ new

@@ -1,14 +1,15 @@ -# encoding: utf-8 +# -*- coding: utf-8 -*- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) require 'bundler' Bundler.setup Bundler.require :default, :test -require "mq" +require "amqp-spec" +require "amqp" amqp_config = File.dirname(__FILE__) + '/amqp.yml' if File.exists? amqp_config class Hash @@ -24,33 +25,36 @@ AMQP_OPTS = YAML::load_file(amqp_config).symbolize_keys[:test] else AMQP_OPTS = {:host => 'localhost', :port => 5672} end +# +# Ruby version-specific +# -if RUBY_VERSION == "1.8.7" +case RUBY_VERSION +when "1.8.7" then module ArrayExtensions def sample self.choice end # sample end class Array include ArrayExtensions end -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 - - -# Shorthand for mocking subject's instance variable -def subject_mock(name, as_null = false) - mock = mock(name) - mock.as_null_object if as_null - subject.instance_variable_set(name.to_sym, mock) - mock + 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) @@ -71,26 +75,6 @@ # 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 - -require "stringio" - -def capture_stdout(&block) - $stdout = StringIO.new - block.call - $stdout.rewind - result = $stdout.read - $stdout = STDOUT - return result -end - -def capture_stderr(&block) - $stderr = StringIO.new - block.call - $stderr.rewind - result = $stderr.read - $stderr = STDOUT - return result end