summaryrefslogtreecommitdiff
path: root/spec/shogun/github_score_spec.rb
blob: 60deb1152594df800ef26297e98dfa92e3f16a68 (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
27
28
29
30
31
RSpec.describe Shogun::GithubScore do
  describe "#score" do
    subject(:github_score) { described_class.new(handle) }
    let(:handle) { "tenderlove" }

    context "when calculating the score for a known user" do
      let(:events) { [{type: 'PushEvent'}, {type: 'IssuesEvent'}] }

      before do
        stub_request(:get, "https://api.github.com/users/#{handle}/events/public")
          .to_return(status: 200, body: events.to_json)
      end

      it { expect(github_score.score).to eq(4) }
    end

    context "when attempting to retrive the score for an unknown user" do
      before do
        stub_request(:get, "https://api.github.com/users/#{handle}/events/public")
          .to_return(status: 404, body: {
            "message": "Not Found",
            "documentation_url": "https://docs.github.com/rest/reference/activity#list-public-events-for-a-user"
          }.to_json)
      end

      it { expect { github_score.score }.to raise_error(Shogun::UserNotFound) }
    end

    # it times out
  end
end