test/specs/yomu.rb in yomu-0.1.3 vs test/specs/yomu.rb in yomu-0.1.4

- old
+ new

@@ -1,10 +1,14 @@ require_relative '../helper.rb' describe Yomu do let(:data) { File.read 'test/samples/sample.pages' } + before do + ENV['JAVA_HOME'] = nil + end + describe '.read' do it 'reads text' do text = Yomu.read :text, data assert_includes text, 'The quick brown fox jumped over the lazy cat.' @@ -23,59 +27,69 @@ Yomu.new end end it 'accepts a root path' do + yomu = nil + assert_silent do yomu = Yomu.new 'test/samples/sample.pages' - - assert_block { yomu.path? } - assert_block { !yomu.uri? } - assert_block { !yomu.stream? } end + + assert yomu.path? + refute yomu.uri? + refute yomu.stream? end it 'accepts a relative path' do + yomu = nil + assert_silent do yomu = Yomu.new 'test/samples/sample.pages' - - assert_block { yomu.path? } - assert_block { !yomu.uri? } - assert_block { !yomu.stream? } end + + assert yomu.path? + refute yomu.uri? + refute yomu.stream? end it 'accepts a path with spaces' do + yomu = nil + assert_silent do yomu = Yomu.new 'test/samples/sample filename with spaces.pages' - - assert_block { yomu.path? } - assert_block { !yomu.uri? } - assert_block { !yomu.stream? } end + + assert yomu.path? + refute yomu.uri? + refute yomu.stream? end it 'accepts a URI' do + yomu = nil + assert_silent do yomu = Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx' - - assert_block { yomu.uri? } - assert_block { !yomu.path? } - assert_block { !yomu.stream? } end + + assert yomu.uri? + refute yomu.path? + refute yomu.stream? end it 'accepts a stream or object that can be read' do + yomu = nil + assert_silent do File.open 'test/samples/sample.pages', 'r' do |file| yomu = Yomu.new file - - assert_block { yomu.stream? } - assert_block { !yomu.path? } - assert_block { !yomu.uri? } end end + + assert yomu.stream? + refute yomu.path? + refute yomu.uri? end it 'does not accept a path to a missing file' do assert_raises Errno::ENOENT do Yomu.new 'test/sample/missing.pages' @@ -89,53 +103,53 @@ end end end end + describe '.java' do + specify 'with no specified JAVA_HOME' do + assert_equal 'java', Yomu.send(:java) + end + + specify 'with a specified JAVA_HOME' do + ENV['JAVA_HOME'] = '/path/to/java/home' + + assert_equal '/path/to/java/home/bin/java', Yomu.send(:java) + end + end + describe 'initialized with a given path' do let(:yomu) { Yomu.new 'test/samples/sample.pages' } - describe '#text' do - it 'reads text' do - assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.' - end + specify '#text reads text' do + assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.' end - describe '#metadata' do - it 'reads metadata' do - assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type'] - end + specify '#metada reads metadata' do + assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type'] end end describe 'initialized with a given URI' do let(:yomu) { Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx' } - describe '#text' do - it 'reads text' do - assert_includes yomu.text, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.' - end + specify '#text reads text' do + assert_includes yomu.text, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.' end - describe '#metadata' do - it 'reads metadata' do - assert_equal 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', yomu.metadata['Content-Type'] - end + specify '#metadata reads metadata' do + assert_equal 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', yomu.metadata['Content-Type'] end end describe 'initialized with a given stream' do let(:yomu) { Yomu.new File.open('test/samples/sample.pages', 'rb') } - describe '#text' do - it 'reads text' do - assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.' - end + specify '#text reads text' do + assert_includes yomu.text, 'The quick brown fox jumped over the lazy cat.' end - describe '#metadata' do - it 'reads metadata' do - assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type'] - end + specify '#metadata reads metadata' do + assert_equal 'application/vnd.apple.pages', yomu.metadata['Content-Type'] end end end