Sha256: 401ed0a9f632a82b117e727500d8fc5a446978d0fbc4fe8dc3fdec92c9e4a94f

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

module Landable
  describe ScreenshotService do
    let(:publicist_url) { nil }
    let(:screenshot_url) { 'http://google.com/asdf' }
    let(:screenshot_content) { 'screenshot-content' }

    before(:each) do
      Landable.configuration.stub(:publicist_url) { publicist_url }
    end

    describe '#capture' do
      context 'with configured publicist url' do
        let(:publicist_url) { 'http://publicist.foo/' }

        it 'should return a file pointer to the downloaded screenshot' do
          Net::HTTP.should_receive(:post_form) do |uri, params|
            uri.to_s.should == 'http://publicist.foo/api/services/screenshots'
            params.should == {'screenshot[url]' => screenshot_url}

            double('response', code: '200', content_type: 'image/png', body: screenshot_content)
          end

          screenshot = ScreenshotService.capture screenshot_url

          screenshot.should be_a Tempfile
          screenshot.read.should == screenshot_content
        end
      end

      context 'without configured publicist url' do
        it 'should return nil with a warning' do
          Net::HTTP.should_not_receive(:post_form)

          Rails.logger.should_receive(:warn).with(/#{screenshot_url}/)

          ScreenshotService.capture(screenshot_url).should be_nil
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
landable-1.13.1 spec/services/landable/screenshot_service_spec.rb
landable-1.12.3 spec/services/landable/screenshot_service_spec.rb
landable-1.12.2 spec/services/landable/screenshot_service_spec.rb
landable-1.12.1 spec/services/landable/screenshot_service_spec.rb
landable-1.11.1 spec/services/landable/screenshot_service_spec.rb
landable-1.11.0 spec/services/landable/screenshot_service_spec.rb
landable-1.10.0.rc2 spec/services/landable/screenshot_service_spec.rb
landable-1.10.0.rc1 spec/services/landable/screenshot_service_spec.rb
landable-1.9.2 spec/services/landable/screenshot_service_spec.rb
landable-1.9.1 spec/services/landable/screenshot_service_spec.rb
landable-1.9.0 spec/services/landable/screenshot_service_spec.rb
landable-1.9.0.rc2 spec/services/landable/screenshot_service_spec.rb
landable-1.9.0.rc1 spec/services/landable/screenshot_service_spec.rb
landable-1.8.0 spec/services/landable/screenshot_service_spec.rb