require 'spec_helper' describe Sqed do let(:s) {Sqed.new} context 'attributes' do specify '#image' do expect(s).to respond_to(:image) end specify '#pattern' do expect(s).to respond_to(:pattern) end specify '#stage_image' do expect(s).to respond_to(:image) end specify '#stage_boundary' do expect(s).to respond_to(:stage_boundary) end specify '#boundaries' do expect(s).to respond_to(:boundaries) end specify '#auto_detect_border' do expect(s).to respond_to(:auto_detect_border) end specify '#boundary_color' do expect(s).to respond_to(:boundary_color) end end context 'initialization' do specify 'without providing a pattern assigns :standard_cross' do expect(s.pattern).to eq(:standard_cross) end end context '#result' do specify 'without providing an image returns false' do expect(s.result).to eq(false) end end # test intent is to just test wrapping functionality, see # other tests for specifics on finders context '#crop_image (with bordered stage)' do specify 'finds a cropped image smaller than original' do s.image = ImageHelpers.test3_image expect(s.crop_image).to be_truthy expect(s.stage_image.columns < s.image.columns).to be(true) expect(s.stage_image.rows < s.image.rows).to be(true) end specify 'properly sets stage boundaries ' do s.image = ImageHelpers.standard_cross_green s.crop_image # ~ (100,94, 800, 600) expect(s.stage_boundary.x_for(0)).to be_within(2).of 100 expect(s.stage_boundary.y_for(0)).to be_within(2).of 94 expect(s.stage_boundary.width_for(0)).to be_within(2).of 800 expect(s.stage_boundary.height_for(0)).to be_within(2).of 600 end end context 'all together' do let(:image) { ImageHelpers.frost_stage } let(:pattern) { :offset_cross } let(:s) { Sqed.new(image: image, pattern: pattern) } specify '#boundaries returns a Sqed::Boundaries instance' do # s.pattern = :standard_cross expect(s.boundaries.class.name).to eq('Sqed::Boundaries') end specify '#stage_image returns an Magick::Image' do expect(s.stage_image.class.name).to eq('Magick::Image') end specify '#crop_image returns an Magick::Image' do expect(s.crop_image.class.name).to eq('Magick::Image') end specify '#crop_image returns #stage_image' do expect(s.crop_image).to eq(s.stage_image) end context '#result' do let(:r) { s.result } specify 'returns a Sqed::Result' do expect(r.class.name).to eq('Sqed::Result') end context 'extracted data' do specify 'for an :identifier section' do expect(r.text_for(:identifier)).to match('000041196') end specify 'for a specimen section' do expect(r.text_for(:specimen)).to match('Saucier Creek') end specify 'for a curator_metadata section' do expect(r.text_for(:curator_metadata)).to match('Frost Entomological Museum') end end end end end