Я тестирую класс в моем модуле 'RecipientMatcher'.
Очень громоздко приходиться вводить предисловие "RecipientMatcher" перед всеми моими классами.Мне было интересно, есть ли лучший способ?
Сегодняшний код:
ocr_text = 'Jim Baker & Co'
recipient_matches = [
RecipientMatcher::RecipientMatchFound.new(build(:group), RecipientMatcher::MatchObject.new(nil,'Jim'), ocr_text, ocr_text.match(/Jim/)),
RecipientMatcher::RecipientMatchFound.new(build(:group), RecipientMatcher::MatchObject.new(nil, 'Jim Baker & Co'), ocr_text, ocr_text.match(/Jim Baker & Co/)),
RecipientMatcher::RecipientMatchFound.new(build(:group), RecipientMatcher::MatchObject.new(nil, 'Jim Baker'), ocr_text, ocr_text.match(/Jim Baker/)),
]
section_meta_data = RecipientMatcher::PossibleRecipientsCalculator.determine_primary_recipients_in_section(recipient_matches)
primary_recipients = section_meta_data.primary_recipients
expect(true).to eq(true)
Было бы идеально, если бы я мог просто написать это:
RecipientMatcher.magic_method do
ocr_text = 'Jim Baker & Co'
recipient_matches = [
::RecipientMatchFound.new(build(:group), ::MatchObject.new(nil,'Jim'), ocr_text, ocr_text.match(/Jim/)),
::RecipientMatchFound.new(build(:group), ::MatchObject.new(nil, 'Jim Baker & Co'), ocr_text, ocr_text.match(/Jim Baker & Co/)),
::RecipientMatchFound.new(build(:group), ::MatchObject.new(nil, 'Jim Baker'), ocr_text, ocr_text.match(/Jim Baker/)),
]
section_meta_data = ::PossibleRecipientsCalculator.determine_primary_recipients_in_section(recipient_matches)
primary_recipients = section_meta_data.primary_recipients
expect(true).to eq(true)
end