lundi 4 mai 2015

Stubbing Github module for test

In my gem i am using Github gem for GitHub API. I created a EachValidator for checking existency of some URL given:

def validate_each(record, attribute, value)
  return if value.empty? and not opts[:presence]
  if check_github_url value
    repo_data = GithubStats::Parser.parse value
    begin
      Github.repos(user: repo_data[:username], repo: repo_data[:repo]).commits.all
    rescue Github::Error::NotFound => e
  p e
      record.errors[attribute] << error_message
    end
  else
    record.errors[attribute] << error_message
  end
end

Hot to stub Github.repos method to return concrete values? Does change class for some stubbed (responding as I want) will be enough? I was using Mocha but i can't figure it out how to use here.

Aucun commentaire:

Enregistrer un commentaire