From afd0a8ab5f690b9bcc5f49371abd82d41a364f58 Mon Sep 17 00:00:00 2001 From: Federico Ravasio Date: Mon, 7 Oct 2013 10:15:23 +0200 Subject: Just change ENV and restore it afterwards. Stubbing ENV[] is not safe outside MRI. At some point after the stubbing has occurred a backtrace is printed to the ActiveSupport warning log: there Rubinius accesses ENV['RBX_NOCOLOR'] to determine if it should print the backtrace with colors or not, causing the stub to fail. Other implementations might access ENV in a different way too, we just can't predict it. The only thing we can do here is to actually set the ENV with what we want and restore it afterwards. --- activerecord/test/cases/fixtures_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/fixtures_test.rb') diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index e61deb1080..bffff07089 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -253,7 +253,8 @@ class FixturesTest < ActiveRecord::TestCase end def test_fixtures_are_set_up_with_database_env_variable - ENV.stubs(:[]).with("DATABASE_URL").returns("sqlite3:///:memory:") + db_url_tmp = ENV['DATABASE_URL'] + ENV['DATABASE_URL'] = "sqlite3:///:memory:" ActiveRecord::Base.stubs(:configurations).returns({}) test_case = Class.new(ActiveRecord::TestCase) do fixtures :accounts @@ -266,6 +267,8 @@ class FixturesTest < ActiveRecord::TestCase result = test_case.new(:test_fixtures).run assert result.passed?, "Expected #{result.name} to pass:\n#{result}" + ensure + ENV['DATABASE_URL'] = db_url_tmp end end -- cgit v1.2.3