Flesh out some tests

This commit is contained in:
Eric B. Budd 2021-12-08 21:54:17 -06:00 committed by Eric Budd
parent ed124e7389
commit a2a9c6078d
1 changed files with 24 additions and 5 deletions

View File

@ -4,6 +4,8 @@ require 'mocha/minitest'
# This allows the test to pretend that user "jerryberry" is logged in. # This allows the test to pretend that user "jerryberry" is logged in.
ENV['USER'] = 'jerryberry' ENV['USER'] = 'jerryberry'
ENV['EDITOR'] = 'foo/bar'
# Set this before loading the code so that the Config constants load correctly. # Set this before loading the code so that the Config constants load correctly.
$test_corpus_file = "./tests/iris.messages.json" $test_corpus_file = "./tests/iris.messages.json"
@ -34,6 +36,10 @@ describe Config do
_(Config::AUTHOR).must_equal "#{Config::USER}@#{Config::HOSTNAME}" _(Config::AUTHOR).must_equal "#{Config::USER}@#{Config::HOSTNAME}"
end end
it 'has the $EDITOR environment variable' do
_(Config::ENV_EDITOR).must_equal 'foo/bar'
end
describe '.find_files' do describe '.find_files' do
it 'looks up all the Iris message files on the system' do it 'looks up all the Iris message files on the system' do
# I am so sorry about this `expects` clause # I am so sorry about this `expects` clause
@ -97,10 +103,13 @@ describe Corpus do
end end
it 'returns an empty array if the hash is not a parent of any other messages' do it 'returns an empty array if the hash is not a parent of any other messages' do
_(Corpus.find_all_by_parent_hash(nil)).must_equal []
end
it 'returns an empty array if the hash is not found in the corpus' do
_(Corpus.find_all_by_parent_hash('GoofMcDoof')).must_equal [] _(Corpus.find_all_by_parent_hash('GoofMcDoof')).must_equal []
end end
it 'returns an empty array if the hash is not found in the corpus'
it 'returns the messages associated with the parent hash' it 'returns the messages associated with the parent hash'
end end
@ -110,8 +119,13 @@ describe Corpus do
end end
describe 'when an index string is passed in' do describe 'when an index string is passed in' do
it 'returns nil if the topic is not found' it 'returns nil if the topic is not found' do
it 'returns the associated topic' assert_nil Corpus.find_topic_by_id('InvalidTopicId')
end
it 'returns the associated topic' do
_(Corpus.find_topic_by_id(1).message).must_equal 'Test'
end
end end
end end
@ -121,8 +135,13 @@ describe Corpus do
end end
describe 'when a hash string is passed in' do describe 'when a hash string is passed in' do
it 'returns nil if the topic is not found' it 'returns nil if the topic is not found' do
it 'returns the associated topic' assert_nil Corpus.find_topic_by_hash('BadHash')
end
it 'returns the associated topic' do
_(Corpus.find_topic_by_hash("gpY2WW/jGcH+BODgySCwDANJlIM=\n").message).must_equal 'Test'
end
end end
end end
end end