From ebdacbd0ae55a45f0f2fb533cb7e0ae9799b3854 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Fri, 21 Jun 2024 19:49:12 -0400 Subject: [PATCH] Add unit test for Classification, and fix bug that that uncovered --- app/classification.rb | 15 +++++++-------- test/classification_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/classification_test.rb diff --git a/app/classification.rb b/app/classification.rb index 2061e46..1fb7e12 100644 --- a/app/classification.rb +++ b/app/classification.rb @@ -29,31 +29,30 @@ class Classification def author @author end - def def inspect data = [] if nil != @ddc - data.push('Dewey=' + @ddc.to_s) + data.push('Dewey=' + @ddc.to_s.inspect) end if nil != @lcc - data.push('LCC=' + @lcc.to_s) + data.push('LCC=' + @lcc.to_s.inspect) end if nil != @author_grouping - data.push('author_grouping=' + @author_grouping.to_s) + data.push('author_grouping=' + @author_grouping.to_s.inspect) end if nil != @author - data.push('author=' + @author.to_s) + data.push('author=' + @author.to_s.inspect) end if nil != @title_grouping - data.push('title_grouping=' + @title_grouping.to_s) + data.push('title_grouping=' + @title_grouping.to_s.inspect) end if nil != @title - data.push('title=' + @title) + data.push('title=' + @title.inspect) end - return '(Classification:' + data.join(',') + ')' + return '(Classification: ' + data.join(', ') + ')' end def to_s diff --git a/test/classification_test.rb b/test/classification_test.rb new file mode 100644 index 0000000..fd11643 --- /dev/null +++ b/test/classification_test.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "test_helper" +require "classification" + +class ClassificationTest < Minitest::Test + def test_inspect + ddc = "973.3/092 B" + lcc = "E302.6.F7" + author_grouping = "BenjaminFranklin" + author_sort = "Franklin, Benjamin" + title_grouping = "Autobiography_of_Benjamin_Franklin" + title = "Autobiography of Benjamin Franklin" + + classification = Classification.new(ddc, lcc, author_grouping, author_sort, title_grouping, title) + + expected = '(Classification: Dewey="973.3/092 B", LCC="E302.6.F7", author_grouping="BenjaminFranklin", author="Franklin, Benjamin", title_grouping="Autobiography_of_Benjamin_Franklin", title="Autobiography of Benjamin Franklin")' + actual = classification.inspect + + assert_equal expected, actual + end +end -- 2.39.2