Created
January 20, 2011 16:37
-
-
Save cvonkleist/788144 to your computer and use it in GitHub Desktop.
a spec from categorizer_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'categorizer command-line stuff' do | |
it 'should write entity ids to case files' do | |
fake_suggestions = { | |
:jp2 => ['/foo/XX00000011.xml', '/bar/YY00000022.xml'], | |
:tiff => ['/bar/zz.xml', '/foo/abc.xml'] | |
} | |
mock_jp2_output = mock('file') | |
mock_tiff_output = mock('file') | |
File.should_receive(:open).with('case.jp2', 'w').and_yield mock_jp2_output | |
File.should_receive(:open).with('case.tiff', 'w').and_yield mock_tiff_output | |
mock_jp2_output.should_receive(:puts).with ['XX00000011', 'YY00000022'] | |
mock_tiff_output.should_receive(:puts).with ['zz', 'abc'] | |
write_entity_id_files fake_suggestions | |
end | |
end | |
# And this is the code in categorizer.rb that is tested by it: | |
# open +filename+ and yield an output file to the caller | |
def report_file(filename) | |
File.open(filename, 'w') do |out| | |
yield out | |
end | |
end | |
# takes +descriptor_filename+ and returns the entity id it represents | |
def entity_id(descriptor_filename) | |
File.basename(descriptor_filename).split('.').first | |
end | |
# writes a hash of {:case => [entity_id, ...]} and writes each case's entity ids to a file (one entity id per line) | |
def write_entity_id_files(suggestions) | |
suggestions.keys.each do |suggestion| | |
case_filename = 'case.%s' % suggestion | |
descriptor_filenames = suggestions[suggestion] | |
report_file(case_filename) do |out| | |
out.puts descriptor_filenames.collect { |f| entity_id(f) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment