spec/ramesh/image_spec.rb in ramesh-1.1.0 vs spec/ramesh/image_spec.rb in ramesh-1.2.0

- old
+ new

@@ -21,17 +21,21 @@ let(:mask_url) do "http://tokyo-ame.jwa.or.jp/map/msk000.png" end + let(:fixture_image) do + open(fixture_path("lena.png")).read + end + before do stub_request(:get, mesh_url) - .to_return(status: 200, body: open(fixture_path("lena.png")).read) + .to_return(status: 200, body: fixture_image) stub_request(:get, background_url) - .to_return(status: 200, body: open(fixture_path("lena.png")).read) + .to_return(status: 200, body: fixture_image) stub_request(:get, mask_url) - .to_return(status: 200, body: open(fixture_path("lena.png")).read) + .to_return(status: 200, body: fixture_image) end describe "#background_image" do it "should download the background image" do described_class.background_image @@ -45,26 +49,41 @@ expect(a_request(:get, mask_url)).to have_been_made.once end end describe "#initialize" do - it "should composite the moment image" do - described_class.new(image_name) - expect(a_request(:get, mesh_url)).to have_been_made.once - expect(a_request(:get, background_url)).to have_been_made.once - expect(a_request(:get, mask_url)).to have_been_made.once + context "without cached images" do + it "should composite the moment image" do + described_class.new(image_name) + expect(a_request(:get, mesh_url)).to have_been_made.once + expect(a_request(:get, background_url)).to have_been_made.once + expect(a_request(:get, mask_url)).to have_been_made.once + end end + + context "with cached images" do + it "should composite the moment image" do + image = double(composite: true) + background_image = double(composite: image) + mask_image = double(composite: image) + + described_class.new(image_name, background_image, mask_image) + expect(a_request(:get, mesh_url)).to have_been_made.once + expect(a_request(:get, background_url)).not_to have_been_made + expect(a_request(:get, mask_url)).not_to have_been_made + end + end end describe "#save" do before do Dir.mkdir(tmpdir) end it "should save itself to the file" do image = described_class.new(image_name) image.save(tmpdir, image_name) - expect(File.exist?(File.join(tmpdir, "#{image_name}.jpg"))).to be_true + expect(File.exist?(File.join(tmpdir, "#{image_name}.jpg"))).to be_truthy end after do FileUtils.rm_rf(tmpdir) end