From 684f8e94354bb1d8648575b4f224903fab8d2c99 Mon Sep 17 00:00:00 2001 From: Takuya Noguchi Date: Fri, 20 May 2022 09:04:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?yes=5Fconfirmed=3F=20=E3=81=AE=E3=82=AA?= =?UTF-8?q?=E3=83=97=E3=82=B7=E3=83=A7=E3=83=B3(fail=5Fon=5Ferror)?= =?UTF-8?q?=E3=81=AE=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/lib/bizside/task_helper_test.rb | 47 +++++++++++++++++++ lib/bizside/task_helper.rb | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 bizside_test_app/test/lib/bizside/task_helper_test.rb diff --git a/bizside_test_app/test/lib/bizside/task_helper_test.rb b/bizside_test_app/test/lib/bizside/task_helper_test.rb new file mode 100644 index 0000000..4e23b7e --- /dev/null +++ b/bizside_test_app/test/lib/bizside/task_helper_test.rb @@ -0,0 +1,47 @@ +require 'test_helper' +require 'bizside/task_helper' + +# メソッドは全てトップレベルに定義されるため、mainオブジェクトを参照する方法を用意 +MAIN_OBJECT = self + +class Bizside::TaskHelperTest < ActiveSupport::TestCase + def test_yes_confirmed_true + assert MAIN_OBJECT.yes_confirmed?('yes') + assert MAIN_OBJECT.yes_confirmed?('Yes') + assert MAIN_OBJECT.yes_confirmed?('YES') + assert MAIN_OBJECT.yes_confirmed?('y') + assert MAIN_OBJECT.yes_confirmed?('Y') + assert MAIN_OBJECT.yes_confirmed?('true') + assert MAIN_OBJECT.yes_confirmed?('TRUE') + assert MAIN_OBJECT.yes_confirmed?(true) + end + + def test_yes_confirmed_false + assert_not MAIN_OBJECT.yes_confirmed?('no') + assert_not MAIN_OBJECT.yes_confirmed?('No') + assert_not MAIN_OBJECT.yes_confirmed?('NO') + assert_not MAIN_OBJECT.yes_confirmed?('n') + assert_not MAIN_OBJECT.yes_confirmed?('N') + assert_not MAIN_OBJECT.yes_confirmed?('false') + assert_not MAIN_OBJECT.yes_confirmed?('FALSE') + assert_not MAIN_OBJECT.yes_confirmed?(false) + end + + def test_yes_confirmed_fali_on_error + options = { fail_on_error: true } + template = 'yes/no または true/false 形式で入力してください。answer=%s' + + assert MAIN_OBJECT.yes_confirmed?('yes', options) + + assert_not MAIN_OBJECT.yes_confirmed?('no', options) + + assert_equal format(template, answer: 'ok'), + assert_raise(RuntimeError) { MAIN_OBJECT.yes_confirmed?('ok', options) }.message + assert_equal format(template, answer: 'OK'), + assert_raise(RuntimeError) { MAIN_OBJECT.yes_confirmed?('OK', options) }.message + assert_equal format(template, answer: 'ng'), + assert_raise(RuntimeError) { MAIN_OBJECT.yes_confirmed?('ng', options) }.message + assert_equal format(template, answer: 'NG'), + assert_raise(RuntimeError) { MAIN_OBJECT.yes_confirmed?('NG', options) }.message + end +end diff --git a/lib/bizside/task_helper.rb b/lib/bizside/task_helper.rb index 4273b61..03cc8b5 100644 --- a/lib/bizside/task_helper.rb +++ b/lib/bizside/task_helper.rb @@ -203,7 +203,7 @@ def self.yes_confirmed?(yes_value, options = {}) ret = Bizside::Yes.confirmed?(yes_value) if ret.nil? if options[:fail_on_error] - fail "yes/no または true/false 形式で入力してください。answer=#{answer}" + fail "yes/no または true/false 形式で入力してください。answer=#{yes_value}" else ret = false end From b13b7030a7203cbcb7d2872338c07b8020f944f6 Mon Sep 17 00:00:00 2001 From: Takuya Noguchi Date: Fri, 20 May 2022 09:15:27 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=A7?= =?UTF-8?q?=E9=9D=9E=E6=8E=A8=E5=A5=A8=E3=81=AE=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?(StringUtils)=E3=82=92=E5=8F=82=E7=85=A7=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * StringUtils -> Bizside::StringUtils --- bizside_test_app/test/lib/bizside/string_utils_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bizside_test_app/test/lib/bizside/string_utils_test.rb b/bizside_test_app/test/lib/bizside/string_utils_test.rb index c943b03..3d9ba1b 100644 --- a/bizside_test_app/test/lib/bizside/string_utils_test.rb +++ b/bizside_test_app/test/lib/bizside/string_utils_test.rb @@ -8,20 +8,20 @@ def test_rand_string end def test_create_random_alpha_string_case_sensitive_true - s = StringUtils.create_random_alpha_string(10, true) + s = Bizside::StringUtils.create_random_alpha_string(10, true) assert s =~ /\A[A-Za-z]{10}\z/ end def test_create_random_alpha_string_case_sensitive_false - s = StringUtils.create_random_alpha_string(10, false) + s = Bizside::StringUtils.create_random_alpha_string(10, false) assert s =~ /\A[a-z]{10}\z/ end def test_create_random_alpha_string_more_than_26_chars - s = StringUtils.create_random_alpha_string(53, true) + s = Bizside::StringUtils.create_random_alpha_string(53, true) assert s =~ /\A[A-Za-z]{53}\z/ - s = StringUtils.create_random_alpha_string(27, false) + s = Bizside::StringUtils.create_random_alpha_string(27, false) assert s =~ /\A[a-z]{27}\z/ end end