Series exercise "bad practice" enforced by tests

While mentoring the (practice) exercise Series, I found that the test does not rescue the exception in time.

Instead, it forces the bad data given to survive instantiation of the object, and then fail when we later decide to call the slices method.

Click here for the "bad"
  def test_empty_series_is_invalid
    skip
    slice_string = ""
    series = Series.new(slice_string)
    assert_raises ArgumentError do
      series.slices(1)
    end
  end

And instead could be:

Click here for the "better"
  def test_empty_series_is_invalid
    skip
    slice_string = ""
    assert_raises ArgumentError do
      Series.new(slice_string)
    end
  end

The diff:

Click here for the "diff"
diff --git i/series_test.rb w/series_test.rb
index 2a8fc01..d95c9b8 100644
--- i/series_test.rb
+++ w/series_test.rb
@@ -69,9 +69,8 @@ class SeriesTest < Minitest::Test
   def test_empty_series_is_invalid
     skip
     slice_string = ""
-    series = Series.new(slice_string)
     assert_raises ArgumentError do
-      series.slices(1)
+      Series.new(slice_string)
     end
   end
 end

Potential patch for fix:

Click here for proposed patch
From 4112c9a500b2a3834420ec9ed12aef470285f5ad Mon Sep 17 00:00:00 2001
From: KOTP <keeperotphones@gmail.com>
Date: Thu, 29 Dec 2022 22:51:41 -0500
Subject: [PATCH exercism/ruby v1] Series: Fail Early, Fail Fast

Allow the ability to fail as soon as we know we can fail given bad data
via initialization.
---
 exercises/practice/series/series_test.rb | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/exercises/practice/series/series_test.rb b/exercises/practice/series/series_test.rb
index 759b5c52..f93e6240 100644
--- a/exercises/practice/series/series_test.rb
+++ b/exercises/practice/series/series_test.rb
@@ -68,9 +68,8 @@ class SeriesTest < Minitest::Test
   def test_empty_series_is_invalid
     skip
     slice_string = ""
-    series = Series.new(slice_string)
     assert_raises ArgumentError do
-      series.slices(1)
+      Series.new(slice_string)
     end
   end
 end

base-commit: 71130faaf359454ad5689a7601395889459589c2
-- 
2.39.0

Hmmm, intressting idea.

I agree with you that it makes sense that it raises the error when you initialize with an empty string.

What to be aware of this change is that this implies that you have to do error handling at 2 places and that the exemplar has to be updated because of that.

This is a practice exercise, and therefore there is no exemplar.

I considered updating the example.rb file, but put that off until discussion happens, and we agree if we are going to do the work. (Also, just busy with not being busy, at the moment.)