Sha256: d94fc936f01f6135c8d4d8969bac33d141af580100a02ace47c1e375d610af45

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe 'Arguments' do
  let(:user) { 'peter-murach' }
  let(:repo) { 'github-api' }
  let(:api)  { Github::Client::Issues.new user: user, repo: repo }
  let(:body) { '[]' }
  let(:status) { 200 }

  subject { api.milestones }

  context 'with existing arguments' do
    let(:request_path) { "/repos/#{user}/#{repo}/milestones" }

    before {
      stub_get(request_path).to_return(body: body, status: status,
        headers: {content_type: "application/json; charset=utf-8"})
    }

    it { expect(subject.user).to eq user }

    it { expect(subject.repo).to eq repo }

    it 'performs request' do
      subject.list
      a_get(request_path).should have_been_made
    end

    it "does not set argument to nil" do
      subject.list
      expect(subject.user).to eq user
    end
  end

  context 'with new arguments' do
    let(:milestone_id) { 11 }
    let(:request_path) { "/repos/#{user}/#{repo}/milestones/#{milestone_id}" }

    before {
      stub_get(request_path).to_return(:body => body, :status => status,
        :headers => {:content_type => "application/json; charset=utf-8"})
    }

    it { expect { subject.milestone_id }.to raise_error(NoMethodError) }

    it "performs request" do
      subject.get user, repo, milestone_id
      expect(a_get(request_path)).to have_been_made
    end

    it 'reads user & repo settings' do
      subject.get number: milestone_id
      expect(a_get(request_path)).to have_been_made
    end

    it 'reads user & repo and requires milestone_id' do
      expect { subject.get milestone_id }.to raise_error(ArgumentError)
    end

    it 'requires extra parameter' do
      expect { subject.get user, repo }.to raise_error(ArgumentError)
    end

    it 'requires milestone_id to be set' do
      expect { subject.get }.to raise_error(ArgumentError)
    end

    it "passes through extra parameters" do
      subject.get user, repo, milestone_id, :auto_pagination => true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
github_api-0.12.3 spec/integration/arguments_spec.rb
github_api-0.12.2 spec/integration/arguments_spec.rb
github_api-0.12.1 spec/integration/arguments_spec.rb
github_api-0.12.0 spec/integration/arguments_spec.rb