Sha256: 57835b0b269b45a9de8427f5e653f1ac8fe4b13398e08016bf751cb5835964b6

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require "spec_helper"

module Twitchus

  describe Checker do
    context "without a config" do
      let(:checker) { Checker.new }

      it "can tell if a channel is online" do
        stub_request(:get, "https://api.twitch.tv/kraken/streams/scvrush1")
          .to_return(status: 200, body: { "stream" => {} }.to_json)

        checker.should be_online("scvrush1")
      end

      it "can tell if a channel is offline" do
        stub_request(:get, "https://api.twitch.tv/kraken/streams/scvrush1")
          .to_return(status: 200, body: { "stream" => nil }.to_json)

        checker.should_not be_online("scvrush1")
      end

      it "selects online streams from a list" do
        stub_request(:get, "https://api.twitch.tv/kraken/streams/online")
          .to_return(status: 200, body: { "stream" => { "name" => "online"} }.to_json)
        stub_request(:get, "https://api.twitch.tv/kraken/streams/offline")
          .to_return(status: 200, body: { "stream" => nil }.to_json)

        checker.fetch_all(%w(online offline)).should == [ { "name" => "online" } ]
      end
    end

    context "with a config" do
      let(:config)  { Struct.new(:client_key).new("foobarkey") }
      let(:checker) { Checker.new(config) }

      it "appends the client key to base_url" do
        checker.url_for("scvrush1").should == "https://api.twitch.tv/kraken/streams/scvrush1?client_key=foobarkey"
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
twitchus-0.1.5 spec/twitchus/checker_spec.rb
twitchus-0.1.4 spec/twitchus/checker_spec.rb
twitchus-0.1.3 spec/twitchus/checker_spec.rb
twitchus-0.1.2 spec/twitchus/checker_spec.rb
twitchus-0.1.1 spec/twitchus/checker_spec.rb
twitchus-0.1.0 spec/twitchus/checker_spec.rb