Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues Mocking GitHub API Calls #314

Open
mikhailbot opened this issue May 28, 2017 · 0 comments
Open

Issues Mocking GitHub API Calls #314

mikhailbot opened this issue May 28, 2017 · 0 comments

Comments

@mikhailbot
Copy link

mikhailbot commented May 28, 2017

First, thanks for the awesome gem! I'm trying to do some tests that rely on the GitHub API that's causing some issues. In particular the method to retrieve a users stars.

I've got a Sinatra app combined with webmock to reply instead of GitHub:

# frozen_string_literal: true
# source https://robots.thoughtbot.com/how-to-stub-external-services-in-tests

require 'sinatra/base'

class FakeGitHub < Sinatra::Base
  get '/users/:user/starred' do
    json_response 200, 'user_starred.json'
  end

  private

  def json_response(response_code, file_name)
    content_type :json
    status response_code
    File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
  end
end

However, the results from calling github.activity.starring.starred user: username isn't the same as against the real API. I iterate over the results, however the real API I can do this:

starred_repos = github.activity.starring.starred user: username
starred_repos.each do |starred_repo|
    puts starred_repo.name
end

But when mocking it requires this (the repo is inside repo for some reason):

starred_repos = github.activity.starring.starred user: username
starred_repos.each do |starred_repo|
    puts starred_repo.repo.name
end

I'm using JSON pulled directly from the API so not sure what's wrong--hoping you could provide some insight if possible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant