From 388e34f15cda012f2487a4d09d75d2fff76a44e9 Mon Sep 17 00:00:00 2001 From: Vladimir Andrijevik Date: Mon, 25 May 2015 16:09:36 +0200 Subject: [PATCH 1/2] Use puts instead of p for multi-line message --- lib/foreigner/adapter.rb | 4 ++-- test/foreigner/adapter_test.rb | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/foreigner/adapter.rb b/lib/foreigner/adapter.rb index f3a5c7b..75f1dab 100644 --- a/lib/foreigner/adapter.rb +++ b/lib/foreigner/adapter.rb @@ -12,8 +12,8 @@ def load! if registered.key?(configured_name) require registered[configured_name] else - p "Database adapter #{configured_name} not supported. Use:\n" + - "Foreigner::Adapter.register '#{configured_name}', 'path/to/adapter'" + puts "Database adapter #{configured_name} not supported. Use:\n" + + "Foreigner::Adapter.register '#{configured_name}', 'path/to/adapter'" end end diff --git a/test/foreigner/adapter_test.rb b/test/foreigner/adapter_test.rb index 8d6ff3f..9df08de 100644 --- a/test/foreigner/adapter_test.rb +++ b/test/foreigner/adapter_test.rb @@ -8,4 +8,22 @@ class Foreigner::AdapterTest < ActiveSupport::TestCase Foreigner::Adapter.load! end -end \ No newline at end of file + + test "load prints warning message for an unsupported adapter on two lines" do + Foreigner::Adapter.stubs(:configured_name).returns('unsupported') + + output = StringIO.new + with_stdout(output) { Foreigner::Adapter.load! } + + assert_equal 2, output.string.split("\n").length + end + + private + def with_stdout(stream) + oldstdout = $stdout + $stdout = stream + yield + ensure + $stdout = oldstdout + end +end From fc7484da48a5658d6e3ed828aaa9763f8cebae49 Mon Sep 17 00:00:00 2001 From: Vladimir Andrijevik Date: Mon, 25 May 2015 16:20:26 +0200 Subject: [PATCH 2/2] Set ActiveSupport::TestCase.test_order to avoid warning --- test/helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/helper.rb b/test/helper.rb index 3717b9b..e64b8ca 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -42,6 +42,10 @@ def execute(sql, name = nil) end end +if ActiveSupport::TestCase.respond_to?(:test_order=) + ActiveSupport::TestCase.test_order = :random +end + module Foreigner class UnitTest < ActiveSupport::TestCase end @@ -57,4 +61,4 @@ def with_migration(&blk) migration end end -end \ No newline at end of file +end