Sha256: 8d3b55c2687982349b1dcf14da6b1a2b3b3da0cc103701849a467b3fb9b653f7

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require "spec_helper"

describe NPR::API::Message do
  describe "warning" do
    json_fixture do
      <<-JSON
        {
          "id": "203",
          "level": "warning",
          "text": {
            "$text": "Query parameter id='000' is invalid because it is not an integer and was ignored."
          },
          "timestamp": {
            "$text": "1355552691.56"
          }
        }
      JSON
    end
  
    before :each do
      @message = NPR::API::Message.new(@fixture)
    end
  
    it "sets level and id" do
      @message.id.should eq "203"
      @message.level.should eq "warning"
    end
  
    it "returns true for #warning?" do
      @message.warning?.should eq true
    end
    
    it "sets text" do
      @message.text.should match /^Query/
    end
    
    it "sets timestamp" do
      @message.timestamp.should be_a Time
    end
  end
  
  #---------------------------
  
  describe "error" do
    json_fixture do
      <<-JSON
        {
          "id": "310",
          "level": "error",
          "text": {
            "$text": "The API key passed in () was invalid or no API key was passed in.  Please register for a valid API key."
          },
          "timestamp": {
            "$text": "1355554389.89"
          }
        }
      JSON
    end
    
    before :each do
      @message = NPR::API::Message.new(@fixture)
    end
    
    it "is an error" do
      @message.error?.should eq true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
npr-1.1.0 spec/unit/api/message_spec.rb
npr-0.1.2 spec/unit/api/message_spec.rb
npr-0.1.1 spec/unit/api/message_spec.rb
npr-0.1.0 spec/unit/api/message_spec.rb