From 45cb66373d7661ebec9d30ef6d0609f9c9eb72af Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Mon, 11 May 2009 16:56:08 -0400 Subject: [PATCH 1/4] Remove unsplated return value from #get_options! for ruby 1.9 compatibility. --- lib/shoulda/private_helpers.rb | 2 +- test/other/private_helpers_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/shoulda/private_helpers.rb b/lib/shoulda/private_helpers.rb index e48d457f..0bde890f 100644 --- a/lib/shoulda/private_helpers.rb +++ b/lib/shoulda/private_helpers.rb @@ -7,7 +7,7 @@ module Shoulda # :nodoc: opts = (args.last.is_a?(Hash) ? args.pop : {}) wanted.each {|w| ret << opts.delete(w)} raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty? - return *ret + return wanted.size == 1 ? ret.first : ret end end end diff --git a/test/other/private_helpers_test.rb b/test/other/private_helpers_test.rb index f5835997..7bfe6547 100644 --- a/test/other/private_helpers_test.rb +++ b/test/other/private_helpers_test.rb @@ -22,5 +22,11 @@ class PrivateHelpersTest < ActiveSupport::TestCase # :nodoc: get_options!(args, :one) end end + + should "return single wanted option" do + args = [:a, :b, {:class => Object}] + klass = get_options!(args,:class) + assert_equal Object, klass + end end end From 7d9efa4014015fa8fc5922ad287fbf26973aa822 Mon Sep 17 00:00:00 2001 From: Dean Strelau Date: Tue, 2 Jun 2009 22:38:00 -0400 Subject: [PATCH 2/4] Require 'test/unit' before including/extending things into it. On Ruby 1.9, Test::Unit::TestCase subclasses MiniTest::Unit::TestCase. If the true TestCase is not loaded first, you get a "superclass mismatch for class TestCase" because Shoulda defines it without that superclass. --- lib/shoulda/test_unit.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/shoulda/test_unit.rb b/lib/shoulda/test_unit.rb index 88bf35c4..0464c239 100644 --- a/lib/shoulda/test_unit.rb +++ b/lib/shoulda/test_unit.rb @@ -1,3 +1,5 @@ +require 'test/unit' + require 'shoulda/context' require 'shoulda/proc_extensions' require 'shoulda/assertions' From f062a6924e4b4539eef1eb2d318f2b82367e692f Mon Sep 17 00:00:00 2001 From: Dean Strelau Date: Tue, 2 Jun 2009 22:40:21 -0400 Subject: [PATCH 3/4] Update testing boot.rb for Ruby 1.9 compat. This brings the file up-to-date with a freshly generated Rails 2.3.2 boot.rb. --- test/rails_root/config/boot.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/rails_root/config/boot.rb b/test/rails_root/config/boot.rb index cd21fb9e..0ad0f787 100644 --- a/test/rails_root/config/boot.rb +++ b/test/rails_root/config/boot.rb @@ -44,6 +44,7 @@ module Rails def load_initializer require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" Rails::Initializer.run(:install_gem_spec_stubs) + Rails::GemDependency.add_frozen_gem_path end end @@ -67,7 +68,7 @@ module Rails class << self def rubygems_version - Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion + Gem::RubyGemsVersion rescue nil end def gem_version @@ -82,14 +83,14 @@ module Rails def load_rubygems require 'rubygems' - - unless rubygems_version >= '0.9.4' - $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.) + min_version = '1.3.1' + unless rubygems_version >= min_version + $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) exit 1 end rescue LoadError - $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org) + $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) exit 1 end From 13ff067422765a5e113da6e0188b4fc9ca9dccfb Mon Sep 17 00:00:00 2001 From: Dean Strelau Date: Tue, 2 Jun 2009 22:41:17 -0400 Subject: [PATCH 4/4] When searching for test failure, accept either MiniTest::Assertion or Test::Unit::AssertionFailedError for Ruby 1.9 compatibility. --- test/fail_macros.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/fail_macros.rb b/test/fail_macros.rb index 408cdf13..b8b4d6d3 100644 --- a/test/fail_macros.rb +++ b/test/fail_macros.rb @@ -13,7 +13,12 @@ module Shoulda # end def should_fail(&block) context "should fail when trying to run:" do - Shoulda.expected_exceptions = [Test::Unit::AssertionFailedError] + if defined?(Test::Unit::AssertionFailedError) + failures = [Test::Unit::AssertionFailedError] + elsif defined?(MiniTest::Assertion) + failures = [MiniTest::Assertion] + end + Shoulda.expected_exceptions = failures yield block Shoulda.expected_exceptions = nil end