spec/ramesh/client_spec.rb in ramesh-1.2.0 vs spec/ramesh/client_spec.rb in ramesh-1.3.0
- old
+ new
@@ -24,60 +24,99 @@
.to_return(status: 200, body: open(fixture_path("index.js")))
Dir.mkdir(tmpdir)
end
describe "#download_image" do
+ let(:download_image) do
+ client.download_image(minute, tmpdir, filename)
+ end
+
+ let(:minute) do
+ 0
+ end
+
+ let(:filename) do
+ nil
+ end
+
before do
image = double(write: true)
allow(Image).to receive(:download_image).and_return(image)
allow_any_instance_of(Image).to receive(:composite_images).and_return(image)
end
- context "when minute is not specified" do
- it "should download the current image" do
- expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091845").once
- client.download_image(tmpdir)
+ context "when valid minute is specified" do
+ let(:minute) do
+ 30
end
- it "should log the result" do
- expect(logger).to receive(:info).with("Downloaded: 201405091845.jpg")
- client.download_image(tmpdir)
- end
- end
-
- context "when valid minute is specified" do
it "should download the image of the specified minutes ago" do
- expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815").once
- client.download_image(tmpdir, 30)
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "201405091815.jpg").once
+ download_image
end
it "should log the result" do
expect(logger).to receive(:info).with("Downloaded: 201405091815.jpg")
- client.download_image(tmpdir, 30)
+ download_image
end
end
context "when invalid minute is specified" do
+ let(:minute) do
+ 7
+ end
+
it "should raise ArgumentError" do
expect do
- client.download_image(tmpdir, 7)
+ download_image
end.to raise_error ArgumentError
end
end
+
+ context "when filename is specified" do
+ let(:filename) do
+ "out.jpg"
+ end
+
+ it "should download the image with specified name" do
+ expect_any_instance_of(Image).to receive(:save).with(tmpdir, "out.jpg").once
+ download_image
+ end
+ end
end
describe "#download_sequential_images" do
+ let(:download_sequential_images) do
+ client.download_sequential_images(from, to, tmpdir)
+ end
+
context "when valid section is specified" do
+ let(:from) do
+ 0
+ end
+
+ let(:to) do
+ 30
+ end
+
it "should download the images" do
expect_any_instance_of(Client).to receive(:download_image).exactly(7).times
- client.download_sequential_images(tmpdir, 0, 30)
+ download_sequential_images
end
end
context "when invalid section is specified" do
+ let(:from) do
+ 1
+ end
+
+ let(:to) do
+ 2
+ end
+
it "should raise ArgumentError" do
expect do
- client.download_sequential_images(tmpdir, 1, 2)
+ download_sequential_images
end.to raise_error ArgumentError
end
end
end