Sha256: 4a41e5b21feb307718abaf27cb95bb74040a44e1d8ba9bd94adc0ebc9a28eb35

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

class XmlResponseExample < ActiveRestClient::Base
  base_url "http://www.example.com/v1/"
  get :atom, "/atom", fake: %Q{
    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom">

      <title>Example Feed</title>
      <link href="http://example.org/"/>
      <updated>2003-12-13T18:30:02Z</updated>
      <author>
        <name>John Doe</name>
      </author>
      <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>

      <entry>
        <title>Atom-Powered Robots Run Amok</title>
        <link href="http://example.org/2003/12/13/atom03"/>
        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
        <updated>2003-12-13T18:30:02Z</updated>
        <summary>Some text.</summary>
      </entry>

      <entry>
        <title>Something else cool happened</title>
        <link href="http://example.org/2015/08/11/andyjeffries"/>
        <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id>
        <updated>2015-08-11T18:30:02Z</updated>
        <summary>Some other text.</summary>
      </entry>

    </feed>}.strip_heredoc, fake_content_type: "application/xml"
end

describe XmlResponseExample do
  it "should parse the response without error" do
    expect {
      XmlResponseExample.atom
    }.to_not raise_error
  end

  it "provides the feed title" do
    @atom = XmlResponseExample.atom
    expect(@atom.feed.title).to eq("Example Feed")
  end

  it "provides the link's href" do
    @atom = XmlResponseExample.atom
    expect(@atom.feed.link.href).to eq("http://example.org/")
  end

  it "each entry item has a title" do
    @atom = XmlResponseExample.atom
    expect(@atom.feed.entry.class).to eq(ActiveRestClient::ResultIterator)
  end

  it "provides a list of entry items" do
    @atom = XmlResponseExample.atom
    expect(@atom.feed.entry[0].title).to eq("Atom-Powered Robots Run Amok")
    expect(@atom.feed.entry[1].title).to eq("Something else cool happened")
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_rest_client-1.1.12 spec/lib/xml_spec.rb
active_rest_client-1.1.11 spec/lib/xml_spec.rb
active_rest_client-1.1.10 spec/lib/xml_spec.rb