From 117c791625f23ae464f0674b6fa6380ab4e32b95 Mon Sep 17 00:00:00 2001 From: Joey Wendt Date: Sun, 16 Mar 2014 08:48:43 -0500 Subject: [PATCH 1/5] Lazily create test repositories on new cassette recording --- spec/helper.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/helper.rb b/spec/helper.rb index bbedca384..8ecfa096a 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -51,6 +51,20 @@ c.define_cassette_placeholder("") do "10050505050000" end + c.before_http_request(:real?) do |request| + next if request.headers['X-Vcr-Test-Repo-Setup'] + options = { + :headers => {'X-Vcr-Test-Repo-Setup' => 'true'}, + :auto_init => true + } + if !oauth_client.repository?("#{test_github_login}/#{test_github_repository}", options) + oauth_client.create_repository(test_github_repository, options) + end + if !oauth_client.repository?("#{test_github_org}/#{test_github_repository}", options) + options[:organization] = test_github_org + oauth_client.create_repository(test_github_repository, options) + end + end c.default_cassette_options = { :serialize_with => :json, # TODO: Track down UTF-8 issue and remove From 003144e838a661385bce4d29d347f3ef38407189 Mon Sep 17 00:00:00 2001 From: Joey Wendt Date: Sun, 16 Mar 2014 09:05:08 -0500 Subject: [PATCH 2/5] Ignore test repo setup interactions so they arent saved in cassettes --- spec/helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/helper.rb b/spec/helper.rb index 8ecfa096a..56d617aa6 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -65,6 +65,9 @@ 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 From 56506fa3644380e758ecfed8454fc57ef85e37c6 Mon Sep 17 00:00:00 2001 From: Joey Wendt Date: Fri, 9 May 2014 03:06:23 -0500 Subject: [PATCH 3/5] Make octokit_warn public instead of private So it can be used easily by test helpers --- lib/octokit/client.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 From 5ff40a751d0e3cf93ade439dfcaaa645ae521583 Mon Sep 17 00:00:00 2001 From: Joey Wendt Date: Fri, 9 May 2014 03:17:55 -0500 Subject: [PATCH 4/5] Check and create test repos only when they are needed --- spec/helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/helper.rb b/spec/helper.rb index 56d617aa6..9129e04aa 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -51,8 +51,11 @@ 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 From cc8a8e2a3b0f3bb104fd05a7e26cf09e0de25c1e Mon Sep 17 00:00:00 2001 From: Joey Wendt Date: Fri, 9 May 2014 03:18:52 -0500 Subject: [PATCH 5/5] Provide a notice that test repositories are being created --- spec/helper.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/helper.rb b/spec/helper.rb index 9129e04aa..ea73caddc 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -60,17 +60,25 @@ :headers => {'X-Vcr-Test-Repo-Setup' => 'true'}, :auto_init => true } - if !oauth_client.repository?("#{test_github_login}/#{test_github_repository}", options) + + 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 - if !oauth_client.repository?("#{test_github_org}/#{test_github_repository}", options) + + 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