diff --git a/lib/inferno/dsl/runnable.rb b/lib/inferno/dsl/runnable.rb index 374b72acce..a6e5838101 100644 --- a/lib/inferno/dsl/runnable.rb +++ b/lib/inferno/dsl/runnable.rb @@ -1,6 +1,7 @@ require_relative 'configurable' require_relative 'input_output_handling' require_relative 'resume_test_route' +require_relative '../exceptions' require_relative '../utils/markdown_formatter' module Inferno @@ -202,7 +203,7 @@ def id(new_id = nil) final_id = "#{prefix}#{@base_id}" - raise StandardError, "ID '#{final_id}' exceeds the maximum id length of 255 characters" if final_id.length > 255 + raise Exceptions::InvalidRunnableIdException, final_id if final_id.length > 255 @id = final_id end diff --git a/lib/inferno/exceptions.rb b/lib/inferno/exceptions.rb index cda872f1ff..be2cf498dd 100644 --- a/lib/inferno/exceptions.rb +++ b/lib/inferno/exceptions.rb @@ -113,5 +113,11 @@ def initialize(name, expected_class_names, actual_class) super("Expected '#{name}' to be a #{expected_class_names}, but found a #{actual_class.name}.") end end + + class InvalidRunnableIdException < StandardError + def initialize(id) + super("ID '#{id}' exceeds the maximum id length of 255 characters") + end + end end end diff --git a/spec/inferno/dsl/runnable_spec.rb b/spec/inferno/dsl/runnable_spec.rb index 59af5527cf..3cf5507e7b 100644 --- a/spec/inferno/dsl/runnable_spec.rb +++ b/spec/inferno/dsl/runnable_spec.rb @@ -190,7 +190,9 @@ describe '.id' do it 'raises an error if the id is longer than 255 characters' do - expect { Class.new(Inferno::Test).id('a' * 256) }.to raise_error(StandardError, /length of 255 characters/) + expect do + Class.new(Inferno::Test).id('a' * 256) + end.to raise_error(Inferno::Exceptions::InvalidRunnableIdException, /length of 255 characters/) end end end