Sha256: 38a8351685f8260db5f10b9a5b1784b84b6f5173e2539cf3136890741ba7d5f0

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'helper'

describe MLB::Team, ".all" do
  context "with connection" do
    before do
      stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query}).to_return(:body => fixture("teams.json"))
    end

    after do
      MLB::Team.reset
    end

    it "requests the correct resource" do
      MLB::Team.all
      expect(a_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query})).to have_been_made
    end

    it "returns the correct results" do
      teams = MLB::Team.all
      expect(teams.first.name).to eq "Arizona Diamondbacks"
    end
  end

  context "with timeout" do
    before do
      stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query}).to_timeout
    end

    after do
      MLB::Team.reset
    end

    it "returns the correct results" do
      teams = MLB::Team.all
      expect(teams.first.name).to eq "Arizona Diamondbacks"
    end
  end

  context "without connection" do
    before do
      stub_request(:get, 'http://api.freebase.com/api/service/mqlread').with(:query => {:query => MLB::Team.mql_query}).to_raise(SocketError)
    end

    after do
      MLB::Team.reset
    end

    it "returns the correct results" do
      teams = MLB::Team.all
      expect(teams.first.name).to eq "Arizona Diamondbacks"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mlb-0.6.3 spec/mlb_spec.rb