File: octokit_spec.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (57 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (2)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

describe Octokit do
  before do
    Octokit.reset!
  end

  after do
    Octokit.reset!
  end

  it 'sets defaults' do
    # rubocop:disable Style/HashEachMethods
    #
    # This may look like a `.keys.each` which should be replaced with `#each_key`, but
    # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
    # The class doesn't fulfill the whole `Enumerable` contract.
    Octokit::Configurable.keys.each do |key|
      # rubocop:enable Style/HashEachMethods
      expect(Octokit.instance_variable_get(:"@#{key}")).to eq(Octokit::Default.send(key))
    end
  end

  describe '.client' do
    it 'creates an Octokit::Client' do
      expect(Octokit.client).to be_kind_of Octokit::Client
    end
    it 'caches the client when the same options are passed' do
      expect(Octokit.client).to eq(Octokit.client)
    end
    it 'returns a fresh client when options are not the same' do
      client = Octokit.client
      Octokit.access_token = '87614b09dd141c22800f96f11737ade5226d7ba8'
      client_two = Octokit.client
      client_three = Octokit.client
      expect(client).not_to eq(client_two)
      expect(client_three).to eq(client_two)
    end
  end

  describe '.configure' do
    # rubocop:disable Style/HashEachMethods
    #
    # This may look like a `.keys.each` which should be replaced with `#each_key`, but
    # this doesn't actually work, since `#keys` is just a method we've defined ourselves.
    # The class doesn't fulfill the whole `Enumerable` contract.
    Octokit::Configurable.keys.each do |key|
      # rubocop:enable Style/HashEachMethods
      it "sets the #{key.to_s.gsub('_', ' ')}" do
        Octokit.configure do |config|
          config.send("#{key}=", key)
        end
        expect(Octokit.instance_variable_get(:"@#{key}")).to eq(key)
      end
    end
  end
end