Sha256: cb751f002281eefe1ffad2b6be450ff56bb06f22af0bf3687ec87c60b7b26b27

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

require 'test_helper'

module Garb
  SpecialKlass = Class.new(OpenStruct)

  class ReportResponseTest < MiniTest::Unit::TestCase
    context "A ReportResponse" do
      context "with a report feed" do
        setup do
          @file = File.read(File.join(File.dirname(__FILE__), '..', '..', "/fixtures/report_feed.xml"))
        end

        should "parse results from atom xml" do
          response = ReportResponse.new(@file)
          assert_equal ['33', '2', '1'], response.results.map(&:pageviews)
        end

        should "default to returning an array of OpenStruct objects" do
          response = ReportResponse.new(@file)
          assert_equal [OpenStruct, OpenStruct, OpenStruct], response.results.map(&:class)
        end

        should "return an array of instances of a specified class" do
          response = ReportResponse.new(@file, SpecialKlass)
          assert_equal [SpecialKlass, SpecialKlass, SpecialKlass], response.results.map(&:class)
        end
      end

      should "return an empty array if there are no results" do
        response = ReportResponse.new("result xml")
        Crack::XML.stubs(:parse).with("result xml").returns({'feed' => {'entry' => nil}})

        assert_equal [], response.results
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
garb-0.9.0 test/unit/garb/report_response_test.rb
garb-0.8.5 test/unit/garb/report_response_test.rb
titanous-garb-0.8.7 test/unit/garb/report_response_test.rb
titanous-garb-0.8.5 test/unit/garb/report_response_test.rb
garb-0.8.4 test/unit/garb/report_response_test.rb
garb-0.8.3 test/unit/garb/report_response_test.rb
garb-0.8.2 test/unit/garb/report_response_test.rb
garb-0.8.1 test/unit/garb/report_response_test.rb
garb-0.8.0 test/unit/garb/report_response_test.rb
garb-0.7.6 test/unit/garb/report_response_test.rb