In a mentoring session, we found that the Minitest wasn’t seeing my namespaced InvalidCodonError class.
Minitest::UnexpectedError: NameError: uninitialized constant ProteinTranslationTest::InvalidCodonError
assert_raises(InvalidCodonError) do
^^^^^^^^^^^^^^^^^
/Users/anagy/Exercism/ruby/protein-translation/protein_translation_test.rb:164:in `test_non_existing_codon_cant_translate'
/Users/anagy/Exercism/ruby/protein-translation/protein_translation_test.rb:164:in `test_non_existing_codon_cant_translate'
The temporary fix was that I used the scope operator to dump it in the global namespace, but that doesn’t feel right.
Ruby Code with uninitialized constant
module CodonExceptions
class InvalidCodonError < EncodingError; end
end
class Translation
include CodonExceptions
CYSTEINE = 'Cysteine'
<... SNIP ...>
TYROSINE = 'Tyrosine'
STOP = 'STOP'
CODON_TO_PROTEIN = {
UGU: CYSTEINE,
<... SNIP ... >
UGA: STOP
}
CODON_TO_PROTEIN.default_proc = proc do
raise InvalidCodonError, "InvalidCodonError: Codon must be one of #{CODON_TO_PROTEIN.keys * ', '}"
end