Skip to content

Commit

Permalink
Merge pull request #452 from octokit/lazy-create-test-repos
Browse files Browse the repository at this point in the history
Change the test suite to automatically create test repositories when needed
  • Loading branch information
joeyw committed May 9, 2014
2 parents e17796a + cc8a8e2 commit 9c95001
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/octokit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
28 changes: 28 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@
c.define_cassette_placeholder("<GITHUB_TEST_ORG_TEAM_ID>") 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
Expand Down

0 comments on commit 9c95001

Please sign in to comment.