summaryrefslogtreecommitdiff
path: root/test/downloader_test.rb
blob: 930ad56f8eb74ad611d825f47c1469ad514f9abe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'test_helper'

class DownloaderTest < Minitest::Test

  def test_get_json_requests_and_parses_content
    endpoint = 'http://somehost.com/file.json'
    response = '{ "name": "value" }'
    FakeWeb.register_uri(:get, endpoint, body: response)
    JSON.stubs(:parse).with(response).once

    Dashing::Downloader.get_json(endpoint)
  end

  def test_get_json_raises_on_bad_request
    FakeWeb.register_uri(:get, 'http://dead-host.com/', status: '404')

    assert_raises(OpenURI::HTTPError) do
      Dashing::Downloader.get_json('http://dead-host.com/')
    end
  end

  def test_load_gist_attempts_to_get_the_gist
    Dashing::Downloader.stubs(:get_json).once
    Dashing::Downloader.get_gist(123)
  end
end