spec/capgun/client_spec.rb in capgun-0.0.3 vs spec/capgun/client_spec.rb in capgun-0.1.0
- old
+ new
@@ -72,18 +72,60 @@
estimate = Capgun.estimate("http://example.com/test")
estimate.cost.should == 1
end
+ specify "estimate with options in a block" do
+ stub_request(:post, "https://api.capgun.io/v1/orders/estimate.json").
+ with(:body => '{"viewport":"1024x2048","packages":["images","viewport"],"url":"http://example.com/test"}',
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ to_return(:status => 200, :body => fixture("estimate-with-options.json"), :headers => {})
+
+ estimate = Capgun.estimate("http://example.com/test", :viewport => "200x100") do |options|
+ options.packages = ['images', 'viewport']
+ options.viewport = '1024x2048'
+ end
+ estimate.cost.should == 3
+ end
+
specify "urls are submitted for capture" do
stub_request(:post, "https://api.capgun.io/v1/orders.json").
with(:body => "{\"url\":\"http://example.com/test\"}",
:headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
to_return(:status => 200, :body => fixture("order.json"), :headers => {})
order = Capgun.capture("http://example.com/test")
order.id.should == '4fd20a1288f560177600000a'
order.cost.should == 1
+ end
+
+ specify "capture with options can be in a block" do
+ stub_request(:post, "https://api.capgun.io/v1/orders.json").
+ with(:body => '{"packages":["images","viewport"],"viewport":"1024x2048","url":"http://example.com/test"}',
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ to_return(:status => 200, :body => fixture("order-with-options.json"), :headers => {})
+
+ order = Capgun.capture("http://example.com/test", :packages => [ :images, :viewport ], :viewport => "1024x2048")
+ order.id.should == '4fd20a1288f560177600000a'
+ order.cost.should == 1
+ order.viewport.should == '1024x2048+0+0'
+ order.packages.should == ['base', 'images', 'viewport']
+ end
+
+ specify "capture with options can be in a block" do
+ stub_request(:post, "https://api.capgun.io/v1/orders.json").
+ with(:body => '{"viewport":"1024x2048","packages":["images","viewport"],"url":"http://example.com/test"}',
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ to_return(:status => 200, :body => fixture("order-with-options.json"), :headers => {})
+
+ order = Capgun.capture("http://example.com/test", :viewport => "200x100") do |options|
+ options.packages = ['images', 'viewport']
+ options.viewport = '1024x2048'
+ end
+ order.id.should == '4fd20a1288f560177600000a'
+ order.cost.should == 1
+ order.viewport.should == '1024x2048+0+0'
+ order.packages.should == ['base', 'images', 'viewport']
end
specify "showing a capture order" do
stub_request(:get, "https://api.capgun.io/v1/orders/4fd20a1288f560177600000a.json").
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).