Sha256: a5ce64761403820dc208228baa37ab8890f728a01c900f001bb4fe516594fcbb

Contents?: true

Size: 1.78 KB

Versions: 5

Compression:

Stored size: 1.78 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

module Oembedr
  describe Client do
    let(:valid_resource_url) { "http://www.youtube.com/watch?v=b9XsTtFu64Y" }
    let(:client) { Client.new(valid_resource_url) }

    describe "initialization" do
      it "requires a resource url as a parameter" do
        lambda { Client.new }.should raise_error(ArgumentError)
      end
      it "cracks the url into a ParsedUrl object" do
        client.parsed_url.should be_a_kind_of(ParsedUrl)
      end
    end

    describe "#connection" do
      it "returns a Faraday::Connection object" do
        client.connection.should be_a_kind_of(Faraday::Connection)
      end
      it "sets some basic attributes on the connection" do
        conn = client.connection
        conn.headers.should == {
          "Accept" => "application/json",
          "User-Agent" => "Oembedr Gem #{Oembedr::VERSION}"
        }
        conn.host.should == "www.youtube.com"
      end
    end

    use_vcr_cassette "client", :record => :new_episodes

    describe "#get" do
      it "requests data and parses that JSON" do
        response = client.get
        response.body["type"].should == "video"
        response.body["html"].should_not be_empty
      end
      it "raises an appropriate error if there is a problem" do
        client = Client.new("http://www.youtube.com/foobar?qq=12314332")
        lambda { client.get }.should raise_error(Faraday::Error::ResourceNotFound)
      end
      it "passes through any additional parameters (e.g. size constraints)" do
        client = Client.new("http://www.youtube.com/watch?v=Qi_AAqi0RZM")
        response = client.get({:params => { :maxwidth => "150", :maxheight => "100" }})
        response.body["width"].should <= 150
        response.body["height"].should <= 100
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oembedr-1.1.1 spec/oembedr/client_spec.rb
oembedr-1.1.0 spec/oembedr/client_spec.rb
oembedr-1.0.0 spec/oembedr/client_spec.rb
oembedr-0.0.3 spec/oembedr/client_spec.rb
oembedr-0.0.2 spec/oembedr/client_spec.rb