Sha256: ec588c0298ce7f58e50a051a9831d0cfecc4906ce7043c71291274aac38520de

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe Zelda::Request do
  it "should call HTTParty" do
    HTTParty.should_receive(:get).with("http://zelda.omroep.nl/12345/foo").and_return nil
    Zelda::Request.get('foo')
  end

  it "should remove private attributes" do
    attrs = { 'foo' => "bar", 'created_at' => "foo", 'updated_at' => "bar", 'id' => 10 }
    HTTParty.stub!(:get).and_return(attrs)
    
    attrs = Zelda::Request.get('foo')
    
    attrs['created_at'].should be_nil
    attrs['updated_at'].should be_nil
    attrs['id'].should be_nil
    attrs['foo'].should == 'bar'
  end

  it "should raise an error without an API key" do
    api_key = Zelda.send(:remove_const, :API_KEY)
    lambda { Zelda::Request.get('foo') }.should raise_error("No Zelda::API_KEY specified")
    Zelda::API_KEY = api_key
  end

  it "should raise error given in the response" do
    xml = File.read(File.dirname(__FILE__) + "/../responses/invalid_api_key.xml")
    FakeWeb.register_uri(:get, "http://zelda.omroep.nl/12345/foo", :body => xml, :content_type => "text/xml")
    lambda { Zelda::Request.get('foo') }.should raise_error("Invalid API key specified")
  end
  
  describe "when returning an url" do
    it "should be correct with 1 args" do
      Zelda::Request.parse_url('foo').should == "http://zelda.omroep.nl/12345/foo" 
    end
    
    it "should be correct with 2 args" do
      Zelda::Request.parse_url('foo', 'bar').should == "http://zelda.omroep.nl/12345/foo/bar" 
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zelda-1.4.0 spec/zelda/request_spec.rb