cocoapods-repo-sq 0.0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +13 -0
  4. data/CHANGES.md +0 -0
  5. data/CONTRIBUTING.md +4 -0
  6. data/Gemfile +12 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +84 -0
  9. data/Rakefile +34 -0
  10. data/cocoapods-repo-sq.gemspec +45 -0
  11. data/doc/CocoapodsRepoSq/Downloader/Extensions.html +225 -0
  12. data/doc/CocoapodsRepoSq/Downloader.html +352 -0
  13. data/doc/CocoapodsRepoSq/DownloaderExtensions.html +227 -0
  14. data/doc/CocoapodsRepoSq/Repository.html +970 -0
  15. data/doc/CocoapodsRepoSq/RepositoryStore.html +962 -0
  16. data/doc/CocoapodsRepoSq/Source.html +342 -0
  17. data/doc/CocoapodsRepoSq/SquareExtensions.html +227 -0
  18. data/doc/CocoapodsRepoSq.html +149 -0
  19. data/doc/Pod/Command/RepoSq/Add.html +436 -0
  20. data/doc/Pod/Command/RepoSq/List.html +256 -0
  21. data/doc/Pod/Command/RepoSq/Remove.html +378 -0
  22. data/doc/Pod/Command/RepoSq/Update.html +380 -0
  23. data/doc/Pod/Command/RepoSq.html +157 -0
  24. data/doc/Pod/Command.html +137 -0
  25. data/doc/Pod/Downloader/Square.html +334 -0
  26. data/doc/Pod/Downloader/SquareExtensions.html +218 -0
  27. data/doc/Pod/Downloader.html +105 -0
  28. data/doc/Pod/SquareSource.html +416 -0
  29. data/doc/Pod.html +146 -0
  30. data/doc/_index.html +256 -0
  31. data/doc/class_list.html +51 -0
  32. data/doc/css/common.css +1 -0
  33. data/doc/css/full_list.css +58 -0
  34. data/doc/css/style.css +499 -0
  35. data/doc/file.README.html +132 -0
  36. data/doc/file_list.html +56 -0
  37. data/doc/frames.html +17 -0
  38. data/doc/index.html +132 -0
  39. data/doc/js/app.js +248 -0
  40. data/doc/js/full_list.js +216 -0
  41. data/doc/js/jquery.js +4 -0
  42. data/doc/method_list.html +291 -0
  43. data/doc/top-level-namespace.html +110 -0
  44. data/lib/cocoapods_plugin.rb +49 -0
  45. data/lib/cocoapods_repo_sq/downloader.rb +86 -0
  46. data/lib/cocoapods_repo_sq/repository.rb +109 -0
  47. data/lib/cocoapods_repo_sq/repository_store.rb +170 -0
  48. data/lib/cocoapods_repo_sq/source.rb +42 -0
  49. data/lib/cocoapods_repo_sq.rb +26 -0
  50. data/lib/pod/command/repo_sq/add.rb +87 -0
  51. data/lib/pod/command/repo_sq/list.rb +55 -0
  52. data/lib/pod/command/repo_sq/remove.rb +61 -0
  53. data/lib/pod/command/repo_sq/update.rb +62 -0
  54. data/lib/pod/command/repo_sq.rb +38 -0
  55. data/spec/spec_helper.rb +80 -0
  56. data/spec/test-repos/repo-1/.settings.yml +4 -0
  57. data/spec/test-repos/repo-2/.settings.yml +4 -0
  58. data/spec/unit/cocoapods_plugin_spec.rb +108 -0
  59. data/spec/unit/cocoapods_repo_sq/downloader_spec.rb +57 -0
  60. data/spec/unit/cocoapods_repo_sq/repository_spec.rb +57 -0
  61. data/spec/unit/cocoapods_repo_sq/repository_store_spec.rb +124 -0
  62. data/spec/unit/cocoapods_repo_sq/source_spec.rb +35 -0
  63. data/spec/unit/pod/command/add_spec.rb +73 -0
  64. data/spec/unit/pod/command/list_spec.rb +70 -0
  65. data/spec/unit/pod/command/remove_spec.rb +47 -0
  66. data/spec/unit/pod/command/update_spec.rb +49 -0
  67. metadata +184 -0
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ module Pod
23
+ class Command
24
+ class RepoSq < Command
25
+ # Subclass of {RepoSq}
26
+ # Provides support for the `pod repo-sq list` command, which lists the
27
+ # Square SDK repositories currently registered on the user's cocoapods
28
+ # local repositories store.
29
+ class List < RepoSq
30
+ self.summary = 'List configured Square SDK repositories'
31
+
32
+ self.description = <<-DESC
33
+ List all Square SDK repositories added to your local Cocoapod's sources registry.
34
+ DESC
35
+
36
+ # Lists all Square SDK repositories registered on the current user
37
+ # {CocoapodsRepoSq::RepositoryStore}.
38
+ def run
39
+ repositories = repository_store.list
40
+
41
+ repositories.each do |repository|
42
+ UI.title "Square SDK repository: #{repository.name}" do
43
+ UI.puts " - URL: #{repository.url}"
44
+ UI.puts " - Path: #{repository.path}"
45
+ end
46
+ end
47
+ UI.puts "\n"
48
+
49
+ n = repositories.length
50
+ UI.puts "#{n} #{n != 1 ? 'repositories' : 'repository'}".green
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ #
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ module Pod
23
+ class Command
24
+ class RepoSq < Command
25
+ # Subclass of {RepoSq}
26
+ # Provides support for the `pod repo-sq remove` command, which removes
27
+ # the targeted Square SDK repository from the user's cocoapods local
28
+ # repositories store.
29
+ class Remove < RepoSq
30
+ self.summary = 'Remove a Square SDK repository'
31
+
32
+ self.description = <<-DESC
33
+ Removes the Square SDK repository for your application `NAME`.
34
+ DESC
35
+
36
+ self.arguments = [
37
+ CLAide::Argument.new('NAME', true),
38
+ ]
39
+
40
+ def initialize(argv)
41
+ @name = argv.shift_argument
42
+ super
43
+ end
44
+
45
+ # Validates that the required argument `NAME` is present.
46
+ def validate!
47
+ super
48
+ help! '`NAME` is required.' unless @name
49
+ end
50
+
51
+ # Removes a Square SDK repository from the current user
52
+ # {CocoapodsRepoSq::RepositoryStore}.
53
+ def run
54
+ UI.section("Removing Square SDK repository `#{@name}`") do
55
+ repository_store.remove(@name)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ module Pod
23
+ class Command
24
+ class RepoSq < Command
25
+ # Subclass of {RepoSq}
26
+ # Provides support for the `pod repo-sq remove` command, which updates
27
+ # the targeted Square SDK repository on the user's cocoapods local
28
+ # repositories store.
29
+ class Update < RepoSq
30
+ self.summary = 'Update Square SDK repository specs'
31
+
32
+ self.description = <<-DESC
33
+ Updates Square SDK repository for your application `NAME`.
34
+ DESC
35
+
36
+ self.arguments = [
37
+ CLAide::Argument.new('NAME', true),
38
+ ]
39
+
40
+ def initialize(argv)
41
+ @name = argv.shift_argument
42
+ super
43
+ end
44
+
45
+ # Validates that the required argument `NAME` is present.
46
+ def validate!
47
+ super
48
+ help! '`NAME` is required.' unless @name
49
+ end
50
+
51
+ # Updates the podspecs of Square SDK repository on the current user
52
+ # {CocoapodsRepoSq::RepositoryStore}.
53
+ def run
54
+ UI.section("Updating Square SDK repository `#{@name}`") do
55
+ repository = repository_store.get(@name)
56
+ repository.update_specs
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright 2018 Square Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ require 'pod/command/repo_sq/add'
18
+ require 'pod/command/repo_sq/list'
19
+ require 'pod/command/repo_sq/remove'
20
+ require 'pod/command/repo_sq/update'
21
+
22
+ module Pod
23
+ class Command
24
+ # Subclass of Pod::Command to provide `pod repo-sq` command to manage Square SDK repositories
25
+ #
26
+ class RepoSq < Command
27
+ self.abstract_command = true
28
+
29
+ self.summary = 'Manage Square SDK repositories'
30
+ self.default_subcommand = 'list'
31
+
32
+ private
33
+ def repository_store
34
+ @repository_store ||= CocoapodsRepoSq::RepositoryStore.default
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,80 @@
1
+ # coding: utf-8
2
+ #
3
+ # Copyright 2018 Square Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ require 'simplecov'
18
+ SimpleCov.start
19
+
20
+ require 'pathname'
21
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
22
+ $:.unshift((ROOT + 'lib').to_s)
23
+ $:.unshift((ROOT + 'spec').to_s)
24
+
25
+ require 'bundler/setup'
26
+ require 'bacon'
27
+ require 'mocha-on-bacon'
28
+ require 'pretty_bacon'
29
+ require 'cocoapods'
30
+
31
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
32
+
33
+ require 'cocoapods_plugin'
34
+
35
+ TEST_REPOS_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'test-repos'))
36
+ CocoapodsRepoSq::RepositoryStore.class_eval do
37
+ @default = new(TEST_REPOS_PATH)
38
+ end
39
+
40
+ #-----------------------------------------------------------------------------#
41
+
42
+ module Pod
43
+
44
+ # Disable the wrapping so the output is deterministic in the tests.
45
+ #
46
+ UI.disable_wrap = true
47
+
48
+ # Redirects the messages to an internal store.
49
+ #
50
+ module UI
51
+ @output = []
52
+ @warnings = []
53
+
54
+ class << self
55
+ attr_accessor :output
56
+ attr_accessor :warnings
57
+
58
+ def puts(message = '')
59
+ @output << "#{message}\n"
60
+ end
61
+
62
+ def warn(message = '', actions = [])
63
+ @warnings << "#{message}\n"
64
+ end
65
+
66
+ def print(message)
67
+ @output << message
68
+ end
69
+
70
+ def reset
71
+ self.title_level = 0
72
+ self.output.clear
73
+ self.warnings.clear
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ #-----------------------------------------------------------------------------#
80
+
@@ -0,0 +1,4 @@
1
+ :name: repo-1
2
+ :username: app-1
3
+ :password: pass-1
4
+ :url: http://app-1.com/
@@ -0,0 +1,4 @@
1
+ :name: repo-2
2
+ :username: app-2
3
+ :password: pass-2
4
+ :url: http://app-2.com/
@@ -0,0 +1,108 @@
1
+ # coding: utf-8
2
+
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ describe 'Plugin Hook' do
23
+ before do
24
+ CocoapodsRepoSq::Repository.current = nil
25
+ end
26
+
27
+ describe 'registration' do
28
+ it 'should register plugin as a :source_provider' do
29
+ Pod::HooksManager.registrations.should.include(:source_provider)
30
+ Pod::HooksManager.registrations[:source_provider][0].plugin_name.should.equal('cocoapods-repo-sq')
31
+ end
32
+ end
33
+
34
+ describe 'installation' do
35
+ before { @block = Pod::HooksManager.registrations[:source_provider][0].block }
36
+
37
+ it 'should fail when `repository` is not provided' do
38
+ lambda { @block.call(nil, {}) }.
39
+ should.raise(Pod::Informative).
40
+ message.should.match /repository is needed for `cocoapods-repo-sq`/
41
+ end
42
+
43
+ it 'should fail when a repository does not exist for `repository`' do
44
+ lambda { @block.call(nil, { 'repository' => 'non-existant' }) }.
45
+ should.raise(Pod::Informative).
46
+ message.should.match /Square SDK repository `non-existant` does not exist/
47
+ end
48
+
49
+ it 'should set the current repository and configure a CocoapodsRepoSq::Source' do
50
+ context = mock('context')
51
+ context.expects(:add_source)
52
+
53
+ CocoapodsRepoSq::Repository.current.should.be.nil?
54
+ @block.call(context, { 'repository' => 'repo-1' })
55
+ CocoapodsRepoSq::Repository.current.should.not.be.nil?
56
+ end
57
+
58
+ it 'should update repository specs when running `pod update`' do
59
+ repository_name = 'repo-1'
60
+ repository = mock('repository')
61
+ repository.expects(:update_specs)
62
+ repository.expects(:path).returns('/path')
63
+ store = CocoapodsRepoSq::RepositoryStore.default
64
+ store.expects(:exists?).with(repository_name).returns(true)
65
+ store.expects(:get).with(repository_name).returns(repository)
66
+ context = mock('context')
67
+ context.expects(:add_source)
68
+ ARGV = ['update']
69
+
70
+ CocoapodsRepoSq::Repository.current.should.be.nil?
71
+ @block.call(context, { 'repository' => repository_name })
72
+ CocoapodsRepoSq::Repository.current.should.not.be.nil?
73
+ end
74
+
75
+ it 'should update repository specs when running `pod install --repo-update`' do
76
+ repository_name = 'repo-1'
77
+ repository = mock('repository')
78
+ repository.expects(:update_specs)
79
+ repository.expects(:path).returns('/path')
80
+ store = CocoapodsRepoSq::RepositoryStore.default
81
+ store.expects(:exists?).with(repository_name).returns(true)
82
+ store.expects(:get).with(repository_name).returns(repository)
83
+ context = mock('context')
84
+ context.expects(:add_source)
85
+ ARGV = ['install', '--repo-update']
86
+
87
+ CocoapodsRepoSq::Repository.current.should.be.nil?
88
+ @block.call(context, { 'repository' => repository_name })
89
+ CocoapodsRepoSq::Repository.current.should.not.be.nil?
90
+ end
91
+
92
+ it 'should not update repository specs when running `pod update --no-repo-update`' do
93
+ repository_name = 'repo-1'
94
+ repository = mock('repository')
95
+ repository.expects(:path).returns('/path')
96
+ store = CocoapodsRepoSq::RepositoryStore.default
97
+ store.expects(:exists?).with(repository_name).returns(true)
98
+ store.expects(:get).with(repository_name).returns(repository)
99
+ context = mock('context')
100
+ context.expects(:add_source)
101
+ ARGV = ['--no-repo-update', '--verbose', 'update']
102
+
103
+ CocoapodsRepoSq::Repository.current.should.be.nil?
104
+ @block.call(context, { 'repository' => repository_name })
105
+ CocoapodsRepoSq::Repository.current.should.not.be.nil?
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ module CocoapodsRepoSq
23
+ describe Downloader do
24
+ before do
25
+ store = RepositoryStore.default
26
+ @repository = store.get('repo-1')
27
+ Repository.current = store.get('repo-2')
28
+ end
29
+
30
+ it 'registers Square in the list of downloaders' do
31
+ Pod::Downloader.downloader_class_by_key.should.include :square
32
+ Pod::Downloader.downloader_class_by_key[:square].should.equal Downloader
33
+ end
34
+
35
+ it 'should download a file from the provided repository' do
36
+ dest_path = File.join(File.dirname(__FILE__))
37
+ downloader = Downloader.new(dest_path, "specs-resource.zip", :repository => @repository)
38
+
39
+ output_file = Pathname(File.join(dest_path, 'file.zip'))
40
+ downloader.expects(:curl!).with('-u', "app-1:pass-1", '-f', '-L', '-o', output_file, 'http://app-1.com/specs-resource.zip', '--create-dirs', '--netrc-optional')
41
+ downloader.expects(:unzip!).with(output_file, '-d', Pathname(dest_path))
42
+
43
+ downloader.download
44
+ end
45
+
46
+ it 'should download a file from the current repository when none if provided' do
47
+ dest_path = File.join(File.dirname(__FILE__))
48
+ downloader = Downloader.new(dest_path, "specs-resource.zip", {})
49
+
50
+ output_file = Pathname(File.join(dest_path, 'file.zip'))
51
+ downloader.expects(:curl!).with('-u', "app-2:pass-2", '-f', '-L', '-o', output_file, 'http://app-2.com/specs-resource.zip', '--create-dirs', '--netrc-optional')
52
+ downloader.expects(:unzip!).with(output_file, '-d', Pathname(dest_path))
53
+
54
+ downloader.download
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ module CocoapodsRepoSq
23
+ describe Repository do
24
+ before do
25
+ @name = 'repo-1'
26
+ @username = 'app-1'
27
+ @password = 'pass-1'
28
+ @url = 'http://app-1.com'
29
+ @path = '/path/to/repo'
30
+ @repository = Repository.new(@name, @username, @password, @url, @path)
31
+ end
32
+
33
+ it 'should initialize the repository with provided settings' do
34
+ @repository.name.should.equal(@name)
35
+ @repository.username.should.equal(@username)
36
+ @repository.password.should.equal(@password)
37
+ @repository.url.should.equal(@url)
38
+ @repository.path.should.equal(@path)
39
+ end
40
+
41
+ it 'should download specifications when calling update_specs' do
42
+ downloader = mock('downloader')
43
+ downloader.expects(:download)
44
+
45
+ new_specs_path = File.join(@path, 'Specs.new')
46
+ specs_path = File.join(@path, 'Specs')
47
+ CocoapodsRepoSq::Downloader.expects(:new).with(new_specs_path, "specs.zip", :repository => @repository).returns(downloader)
48
+
49
+ FileUtils.expects(:rm_rf).with(new_specs_path)
50
+ FileUtils.expects(:rm).with(File.join(new_specs_path, "file.zip"))
51
+ FileUtils.expects(:rm_rf).with(specs_path)
52
+ FileUtils.expects(:mv).with(new_specs_path, specs_path)
53
+
54
+ @repository.update_specs
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,124 @@
1
+ # coding: utf-8
2
+
3
+ # This source file is part of the cocoapods-repo-sq plugin under the Apache 2.0
4
+ # license:
5
+ #
6
+ # Copyright 2018 Square Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # =============================================================================
21
+
22
+ module CocoapodsRepoSq
23
+ describe RepositoryStore do
24
+ describe 'initialize' do
25
+ it 'should use Cocoapods home directory when nothing is passed' do
26
+ expected_path = File.join(Pod::Config.instance.home_dir, 'repo-sq')
27
+ store = RepositoryStore.new
28
+
29
+ store.instance_eval('@path').should.equal expected_path
30
+ Dir.exists?(expected_path).should.be.true?
31
+ end
32
+
33
+ it 'should allow customizing the base repository path' do
34
+ expected_path = File.join(File.dirname(__FILE__), 'repo-sq')
35
+ store = RepositoryStore.new(expected_path)
36
+
37
+ store.instance_eval('@path').should.equal expected_path
38
+ Dir.exists?(expected_path).should.be.true?
39
+ end
40
+ end
41
+
42
+ describe 'instance methods' do
43
+ before do
44
+ @store = CocoapodsRepoSq::RepositoryStore.default
45
+ @base_path = @store.instance_eval('@path')
46
+ end
47
+
48
+ describe 'exists?' do
49
+ it 'checks for the existence of the settings file' do
50
+ name = 'repo-1'
51
+ File.expects(:exists?).with(File.join(@base_path, name, '.settings.yml')).returns(true)
52
+ @store.exists?(name).should.be.true?
53
+ end
54
+ end
55
+
56
+ describe 'list' do
57
+ it 'lists all existing repositories' do
58
+ repositories = @store.list
59
+ repositories.count.should.equal 2
60
+ repositories.each{ |r| r.should.be.instance_of Repository }
61
+ repositories.map(&:name).sort.should.equal ['repo-1', 'repo-2']
62
+ end
63
+ end
64
+
65
+ describe 'get' do
66
+ it 'returns nil when repository does not exist' do
67
+ repository = @store.get('repo-3')
68
+ repository.should.be.nil?
69
+ end
70
+
71
+ it 'returns a valid repository object when repository exists' do
72
+ repository = @store.get('repo-1')
73
+ repository.should.be.instance_of Repository
74
+ repository.name.should.equal 'repo-1'
75
+ repository.username.should.equal 'app-1'
76
+ repository.password.should.equal 'pass-1'
77
+ repository.url.should.equal 'http://app-1.com/'
78
+ end
79
+ end
80
+
81
+ describe 'register' do
82
+ it 'raises an exception when the repository already exists' do
83
+ lambda{ @store.register('repo-1', 'app-1', 'pass-1', 'url-1') }.
84
+ should.raise(Pod::Informative).
85
+ message.should.match /Square SDK repository `repo-1` is already configured/
86
+ end
87
+
88
+ it 'cleans repository path if it fails to register' do
89
+ error = StandardError.new('error')
90
+ @store.expects(:store_settings!).raises(error)
91
+ @store.expects(:remove).with('repo-4')
92
+
93
+ lambda{ @store.register('repo-4', 'app-4', 'pass-4', 'url-4') }.
94
+ should.raise(StandardError)
95
+ end
96
+
97
+ it 'creates settings file and returns repository when successfully adding it' do
98
+ repository = @store.register('repo-4', 'app-4', 'pass-4', 'url-4')
99
+ repository.name.should.equal 'repo-4'
100
+ repository.username.should.equal 'app-4'
101
+ repository.password.should.equal 'pass-4'
102
+ repository.url.should.equal 'url-4'
103
+ File.exists?(File.join(@base_path, 'repo-4', '.settings.yml')).should.be.true?
104
+ @store.remove('repo-4').should.be.true?
105
+ end
106
+ end
107
+
108
+ describe 'remove' do
109
+ it 'returns false when no repository is removed' do
110
+ @store.remove('repo-7').should.be.false?
111
+ Dir.exists?(File.join(@base_path, 'repo-3')).should.be.false?
112
+ end
113
+
114
+ it 'creates settings file and returns repository when successfully adding it' do
115
+ @store.register('repo-4', 'app-4', 'pass-4', 'url-4')
116
+ File.exists?(File.join(@base_path, 'repo-4', '.settings.yml')).should.be.true?
117
+
118
+ @store.remove('repo-4').should.be.true?
119
+ Dir.exists?(File.join(@base_path, 'repo-4')).should.be.false?
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end