File: shorten_spec.rb

package info (click to toggle)
gist 5.0.0-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 432 kB
  • sloc: ruby: 3,160; makefile: 15
file content (24 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
describe '...' do
  before do
    stub_request(:post, /api\.github.com\/gists/).to_return(:body => '{"html_url": "http://github.com/"}')
  end

  it "should return a shortened version of the URL when response is 200" do
    stub_request(:post, "https://git.io/create").to_return(:status => 200, :body => 'XXXXXX')
    Gist.gist("Test gist", :output => :short_url, anonymous: false).should == "https://git.io/XXXXXX"
  end

  it "should return a shortened version of the URL when response is 201" do
    stub_request(:post, "https://git.io/create").to_return(:status => 201, :headers => { 'Location' => 'https://git.io/XXXXXX' })
    Gist.gist("Test gist", :output => :short_url, anonymous: false).should == "https://git.io/XXXXXX"
  end

  it 'should raise an error when trying to get short urls without being logged in' do
    error_msg = 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
      '(Github now requires credentials to gist https://bit.ly/2GBBxKw)'

    expect do
      Gist.gist("Test gist", output: :short_url, anonymous: true)
    end.to raise_error(StandardError, error_msg)
  end
end