diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index 32559fe3b..68b2043f1 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -308,6 +308,16 @@ def client_secret=(value) @client_secret = value end + # Wrapper around Kernel#warn to print warnings unless + # OCTOKIT_SILENT is set to true. + # + # @return [nil] + def octokit_warn(*message) + unless ENV['OCTOKIT_SILENT'] + warn message + end + end + private def reset_agent @@ -364,15 +374,5 @@ def parse_query_and_convenience_headers(options) opts end - - # Wrapper around Kernel#warn to print warnings unless - # OCTOKIT_SILENT is set to true. - # - # @return [nil] - def octokit_warn(*message) - unless ENV['OCTOKIT_SILENT'] - warn message - end - end end end diff --git a/spec/helper.rb b/spec/helper.rb index bbedca384..ea73caddc 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -51,6 +51,34 @@ c.define_cassette_placeholder("") do "10050505050000" end + + c.before_http_request(:real?) do |request| + next if request.headers['X-Vcr-Test-Repo-Setup'] + next unless request.uri.include? test_github_repository + + options = { + :headers => {'X-Vcr-Test-Repo-Setup' => 'true'}, + :auto_init => true + } + + test_repo = "#{test_github_login}/#{test_github_repository}" + if !oauth_client.repository?(test_repo, options) + Octokit.octokit_warn "NOTICE: Creating #{test_repo} test repository." + oauth_client.create_repository(test_github_repository, options) + end + + test_org_repo = "#{test_github_org}/#{test_github_repository}" + if !oauth_client.repository?(test_org_repo, options) + Octokit.octokit_warn "NOTICE: Creating #{test_org_repo} test repository." + options[:organization] = test_github_org + oauth_client.create_repository(test_github_repository, options) + end + end + + c.ignore_request do |request| + !!request.headers['X-Vcr-Test-Repo-Setup'] + end + c.default_cassette_options = { :serialize_with => :json, # TODO: Track down UTF-8 issue and remove