social_snippet 0.0.9 → 0.0.10

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 (70) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +11 -4
  3. data/README.md +6 -6
  4. data/Rakefile +19 -1
  5. data/lib/social_snippet.rb +11 -0
  6. data/lib/social_snippet/api/install_repository_api.rb +23 -82
  7. data/lib/social_snippet/api/manifest_api.rb +3 -3
  8. data/lib/social_snippet/api/update_repository_api.rb +34 -35
  9. data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +7 -7
  10. data/lib/social_snippet/config.rb +18 -8
  11. data/lib/social_snippet/core.rb +13 -0
  12. data/lib/social_snippet/document.rb +2 -0
  13. data/lib/social_snippet/document_backend.rb +2 -0
  14. data/lib/social_snippet/document_backend/yaml_document.rb +252 -0
  15. data/lib/social_snippet/document_backend/yaml_document/query.rb +45 -0
  16. data/lib/social_snippet/repository.rb +2 -2
  17. data/lib/social_snippet/repository/driver_factory.rb +42 -0
  18. data/lib/social_snippet/repository/drivers.rb +3 -2
  19. data/lib/social_snippet/repository/drivers/driver_base.rb +100 -0
  20. data/lib/social_snippet/repository/drivers/entry.rb +11 -0
  21. data/lib/social_snippet/repository/drivers/git_driver.rb +100 -0
  22. data/lib/social_snippet/repository/models.rb +15 -0
  23. data/lib/social_snippet/repository/models/package.rb +97 -0
  24. data/lib/social_snippet/repository/models/repository.rb +94 -0
  25. data/lib/social_snippet/repository/repository_manager.rb +79 -67
  26. data/lib/social_snippet/resolvers/base_resolver.rb +13 -17
  27. data/lib/social_snippet/rspec/test_document.rb +305 -0
  28. data/lib/social_snippet/rspec/test_driver.rb +76 -0
  29. data/lib/social_snippet/rspec/test_storage.rb +459 -0
  30. data/lib/social_snippet/storage.rb +1 -0
  31. data/lib/social_snippet/storage_backend.rb +3 -0
  32. data/lib/social_snippet/storage_backend/file_system_storage.rb +71 -0
  33. data/lib/social_snippet/storage_backend/storage_base.rb +35 -0
  34. data/lib/social_snippet/version.rb +8 -3
  35. data/spec/helpers/codeclimate_helper.rb +1 -1
  36. data/spec/helpers/fakefs_helper.rb +10 -0
  37. data/spec/helpers/social_snippet_helper.rb +117 -0
  38. data/spec/lib/api/insert_snippet_spec.rb +95 -2
  39. data/spec/lib/api/update_repository_spec.rb +196 -0
  40. data/spec/lib/command_line/sspm_install_spec.rb +169 -180
  41. data/spec/lib/command_line/sspm_update_spec.rb +56 -0
  42. data/spec/lib/config_spec.rb +6 -8
  43. data/spec/lib/core_spec.rb +21 -38
  44. data/spec/lib/file_system_storage_spec.rb +170 -0
  45. data/spec/lib/insert_resolver_spec.rb +15 -2
  46. data/spec/lib/registry_client_spec.rb +6 -9
  47. data/spec/lib/repository/driver_base_spec.rb +89 -0
  48. data/spec/lib/repository/git_driver_spec.rb +10 -0
  49. data/spec/lib/repository/package_spec.rb +172 -0
  50. data/spec/lib/repository/repository_factory_spec.rb +67 -22
  51. data/spec/lib/repository/repository_manager_spec.rb +71 -114
  52. data/spec/lib/repository/repository_spec.rb +191 -0
  53. data/spec/lib/yaml_document_spec.rb +14 -0
  54. data/spec/spec_helper.rb +8 -93
  55. data/test/config_test.rb +6 -7
  56. data/test/driver_base_test.rb +201 -0
  57. data/test/git_driver_test.rb +51 -0
  58. data/test/insert_snippet_test.rb +256 -349
  59. data/test/repository_manager_test.rb +7 -16
  60. data/test/yaml_document_test.rb +97 -0
  61. metadata +44 -16
  62. data/lib/social_snippet/repository/drivers/base_repository.rb +0 -189
  63. data/lib/social_snippet/repository/drivers/git_repository.rb +0 -74
  64. data/lib/social_snippet/repository/repository_factory.rb +0 -59
  65. data/lib/social_snippet/repository/repository_installer.rb +0 -85
  66. data/spec/lib/repository/base_repository_spec.rb +0 -104
  67. data/spec/lib/repository/git_repository_spec.rb +0 -83
  68. data/spec/lib/repository/repository_installer_spec.rb +0 -63
  69. data/test/base_repository_test.rb +0 -375
  70. data/test/git_repository_test.rb +0 -114
@@ -1,224 +1,213 @@
1
1
  require "spec_helper"
2
2
 
3
- module SocialSnippet::CommandLine
3
+ describe ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand do
4
4
 
5
- describe SSpm::SubCommands::InstallCommand do
5
+ before do
6
+ allow_any_instance_of(
7
+ ::SocialSnippet::Registry::RegistryResources::Base
8
+ ).to receive(:rest_client) do
9
+ ::RestClient::Resource.new "http://api.server/api/dummy"
10
+ end
11
+ end
12
+
13
+ describe "$ sspm install" do
6
14
 
7
15
  before do
8
- allow_any_instance_of(
9
- ::SocialSnippet::Registry::RegistryResources::Base
10
- ).to receive(:rest_client) do
11
- ::RestClient::Resource.new "http://api.server/api/dummy"
16
+ allow(fake_core.api).to receive(:resolve_name_by_registry).with("foo") do
17
+ "url-foo"
12
18
  end
13
- end
19
+ allow(fake_core.api).to receive(:resolve_name_by_registry).with("bar") do
20
+ "url-bar"
21
+ end
22
+ end # prepare fake_core.api
14
23
 
15
- let(:my_repo_info) do
16
- {
17
- "name" => "my-repo",
18
- "desc" => "This is new repository.",
19
- "url" => "git://github.com/user/my-repo",
20
- "dependencies" => {
21
- },
22
- }
23
- end # result
24
+ context "create snippet.json" do
24
25
 
25
- before do
26
- WebMock
27
- .stub_request(
28
- :get,
29
- "http://api.server/api/dummy/repositories/my-repo",
30
- )
31
- .to_return(
32
- :status => 200,
33
- :body => my_repo_info.to_json,
34
- :headers => {
35
- "Content-Type" => "application/json",
26
+ before do
27
+ ::FileUtils.touch "snippet.json"
28
+ ::File.write "snippet.json", {
29
+ :dependencies => {
30
+ "foo" => "1.2.3",
31
+ "bar" => "0.0.1"
36
32
  },
37
- )
38
- end # GET /repositories/my-repo/dependencies
39
-
40
- let(:new_repo_info) do
41
- {
42
- "name" => "new-repo",
43
- "desc" => "This is new repository.",
44
- "url" => "git://github.com/user/new-repo",
45
- "dependencies" => {
46
- "my-repo" => "1.0.0",
47
- },
48
- }
49
- end # result
33
+ }.to_json
34
+ end
50
35
 
51
- before do
52
- WebMock
53
- .stub_request(
54
- :get,
55
- "http://api.server/api/dummy/repositories/new-repo",
56
- )
57
- .to_return(
58
- :status => 200,
59
- :body => new_repo_info.to_json,
60
- :headers => {
61
- "Content-Type" => "application/json",
62
- },
63
- )
64
- end # GET /repositories/new-repo/dependencies
36
+ context "prepare command" do
65
37
 
66
- before do
67
- allow(::SocialSnippet::Repository::RepositoryFactory).to receive(:clone).with(/my-repo/) do |url|
68
- class FakeRepo
69
- attr_reader :path
70
- end
38
+ let(:install_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand.new [] }
71
39
 
72
- repo = FakeRepo.new
73
- allow(repo).to receive(:path).and_return "/path/to/my-repo"
74
- allow(repo).to receive(:name).and_return "my-repo"
75
- allow(repo).to receive(:create_cache).and_return ""
76
- allow(repo).to receive(:has_versions?).and_return true
77
- allow(repo).to receive(:latest_version).and_return "1.2.3"
78
- allow(repo).to receive(:dependencies).and_return({})
79
- repo
80
- end
81
- end # prepare my-repo
40
+ context "run command" do
82
41
 
83
- before do
84
- allow(::SocialSnippet::Repository::RepositoryFactory).to receive(:clone).with(/new-repo/) do |url|
85
- class FakeRepo
86
- attr_reader :path
87
- end
42
+ before do
43
+ allow(fake_core.api).to receive(:install_repository)
44
+ end
88
45
 
89
- repo = FakeRepo.new
90
- allow(repo).to receive(:path).and_return "/path/to/new-repo"
91
- allow(repo).to receive(:name).and_return "new-repo"
92
- allow(repo).to receive(:create_cache).and_return ""
93
- allow(repo).to receive(:has_versions?).and_return true
94
- allow(repo).to receive(:latest_version).and_return "1.2.4"
95
- allow(repo).to receive(:dependencies).and_return new_repo_info["dependencies"]
96
- repo
97
- end
98
- end # prepare new-repo
46
+ before do
47
+ install_command.init
48
+ install_command.run
49
+ end
99
50
 
100
- before do
101
- allow(::FileUtils).to receive(:cp_r) do
102
- # do nothing
103
- end
104
- end
51
+ it { expect(fake_core.api).to have_received(:install_repository).with("url-foo", "1.2.3", kind_of(::Hash)).once }
52
+ it { expect(fake_core.api).to have_received(:install_repository).with("url-bar", "0.0.1", kind_of(::Hash)).once }
105
53
 
106
- #
107
- # main
108
- #
109
- let(:install_command_output) { ::StringIO.new }
110
- let(:install_command_logger) { ::SocialSnippet::Logger.new install_command_output }
111
- before { allow(fake_core).to receive(:logger).and_return install_command_logger }
54
+ context "re-install" do
112
55
 
113
- describe "$ sspm install" do
56
+ let(:re_install_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand.new [] }
114
57
 
115
- context "create snippet.json" do
58
+ before do
59
+ re_install_command.init
60
+ re_install_command.run
61
+ end
116
62
 
117
- before do
118
- FileUtils.touch "snippet.json"
119
- File.write "snippet.json", {
120
- :dependencies => {
121
- "foo" => "1.2.3",
122
- "bar" => "0.0.1"
123
- },
124
- }.to_json
125
- end
63
+ it { expect(fake_core.api).to have_received(:install_repository).with("url-foo", "1.2.3", kind_of(::Hash)).twice }
64
+ it { expect(fake_core.api).to have_received(:install_repository).with("url-bar", "0.0.1", kind_of(::Hash)).twice }
126
65
 
127
- example do
128
- install_command = SSpm::SubCommands::InstallCommand.new([])
129
- expect(fake_core.api).to receive(:install_repository_by_name).with("foo", "1.2.3", kind_of(Hash)).once
130
- expect(fake_core.api).to receive(:install_repository_by_name).with("bar", "0.0.1", kind_of(Hash)).once
131
- install_command.run
132
- end
66
+ end # re-install
67
+
68
+ end # run command
69
+
70
+ end # prepare command
133
71
 
134
- end # create snippet.json
72
+ end # create snippet.json
135
73
 
136
- end # $ sspm install
74
+ end # $ sspm install
137
75
 
138
- describe "$ sspm install my-repo" do
76
+ describe "$ sspm install my-repo" do
139
77
 
140
- let(:install_command_output) { ::StringIO.new }
141
- let(:install_command_logger) { ::SocialSnippet::Logger.new install_command_output }
78
+ context "prepare registry info" do
142
79
 
143
80
  before do
144
- install_command_logger.level = ::SocialSnippet::Logger::Severity::INFO
145
- allow(fake_core).to receive(:logger).and_return install_command_logger
146
- install_command = SSpm::SubCommands::InstallCommand.new ["my-repo"]
147
- install_command.init
148
- install_command.run
81
+ allow(fake_core.api).to receive(:resolve_name_by_registry).with("my-repo") do
82
+ "git://driver.test/user/my-repo"
83
+ end
149
84
  end
150
85
 
151
- subject { install_command_output.string }
152
- it { should match(/my-repo/) }
153
- it { should match(/Installing/) }
154
- it { should match(/Cloning/) }
155
- it { should match(/Success/) }
156
- it { should_not match(/dependencies/) }
157
-
158
- context "$ sspm install my-repo (second)" do
159
-
160
- let(:second_install_command_output) { ::StringIO.new }
161
- let(:second_install_command_logger) { ::SocialSnippet::Logger.new second_install_command_output }
162
-
163
- subject do
164
- install_command_logger.level = ::SocialSnippet::Logger::Severity::INFO
165
- allow(fake_core).to receive(:logger).and_return second_install_command_logger
166
- install_command = SSpm::SubCommands::InstallCommand.new ["my-repo"]
167
- install_command.init
168
- install_command.run
169
- second_install_command_output.string
86
+ before do
87
+ allow(fake_core.api).to receive(:install_repository)
88
+ end
89
+
90
+ context "prepare command" do
91
+ let(:install_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand.new ["my-repo"] }
92
+ before { install_command.init }
93
+ context "run command" do
94
+ before { install_command.run }
95
+ it { expect(fake_core.api).to have_received(:install_repository).with("git://driver.test/user/my-repo", nil, kind_of(::Hash)).once }
170
96
  end
97
+ end # prepare command
171
98
 
172
- it { should match(/my-repo/) }
173
- it { should_not match(/Installing/) }
174
- it { should_not match(/Cloning/) }
175
- it { should_not match(/Success/) }
176
- it { should_not match(/dependencies/) }
99
+ end # prepare registry info
177
100
 
178
- end # (reinstall) $ sspm install my-repo
101
+ end # $ sspm install my-repo
179
102
 
180
- end # $ sspm install my-repo
103
+ describe "package dependencies" do
181
104
 
182
- describe "$ sspm install new-repo" do
105
+ context "prepare registry info" do
183
106
 
184
107
  before do
185
- install_command = SSpm::SubCommands::InstallCommand.new ["new-repo"]
186
- install_command.init
187
- install_command.run
108
+ allow(fake_core.api).to receive(:resolve_name_by_registry).with("my-repo") do
109
+ "git://driver.test/user/my-repo"
110
+ end
111
+ allow(fake_core.api).to receive(:resolve_name_by_registry).with("new-repo") do
112
+ "git://driver.test/user/new-repo"
113
+ end
188
114
  end
189
115
 
190
- subject { install_command_output.string }
191
- it { should match(/my-repo/) }
192
- it { should match(/new-repo/) }
193
- it { should match(/my-repo.*new-repo/m) }
194
- it { should match(/Installing: new-repo#1.2.4/) }
195
- it { should match(/Installing: my-repo#1.0.0/) }
196
- it { should match(/Cloning/) }
197
- it { should match(/Success/) }
198
- it { should match(/Finding new-repo#1.2.4's/) }
116
+ context "already installed my-repo" do
199
117
 
200
- end # $ sspm install new-repo
118
+ before do
119
+ repo = ::SocialSnippet::Repository::Models::Repository.find_or_create_by(:name => "my-repo")
120
+ repo.add_ref "1.2.3", "rev-1.2.3"
121
+ repo.add_package "1.2.3"
122
+ ::SocialSnippet::Repository::Models::Package.create(
123
+ :repo_name => "my-repo",
124
+ :rev_hash => "rev-1.2.3",
125
+ )
126
+ end
201
127
 
202
- describe "$ sspm install --dry-run new-repo" do
128
+ context "install new-repo" do
203
129
 
204
- before do
205
- install_command = SSpm::SubCommands::InstallCommand.new ["--dry-run", "new-repo"]
206
- install_command.init
207
- install_command.run
208
- end
130
+ let(:install_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand.new ["new-repo"] }
131
+ before { install_command.init }
132
+
133
+ context "prepare stubs" do
134
+
135
+ before do
136
+ allow(fake_core.repo_manager).to receive(:install).with("git://driver.test/user/new-repo", nil, kind_of(::Hash)).once do
137
+ pkg = ::SocialSnippet::Repository::Models::Package.new
138
+ pkg.add_dependency "my-repo", "1.2.3"
139
+ pkg
140
+ end
141
+ end
142
+
143
+ before do
144
+ allow(fake_core.api).to receive(:install_repository).and_call_original
145
+ end
146
+
147
+ context "run-command" do
148
+ before { install_command.run }
149
+ it { expect(fake_core.api).to_not have_received(:install_repository).with("git://driver.test/user/my-repo", "1.2.3", kind_of(::Hash)) }
150
+ it { expect(fake_core.api).to have_received(:install_repository).with("git://driver.test/user/new-repo", nil, kind_of(::Hash)).once }
151
+ end
152
+
153
+ end # prepare stubs
154
+
155
+ end # prepare args
156
+
157
+ end # already installed my-repo
158
+
159
+ context "install new-repo" do
160
+
161
+ let(:install_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand.new ["new-repo"] }
162
+ before { install_command.init }
163
+
164
+ context "prepare stubs" do
165
+
166
+ before do
167
+ allow(fake_core.repo_manager).to receive(:install).with("git://driver.test/user/my-repo", "1.2.3", kind_of(::Hash)) do
168
+ repo = ::SocialSnippet::Repository::Models::Repository.find_or_create_by(:name => "my-repo")
169
+ repo.add_ref "1.2.3", "rev-1.2.3"
170
+ repo.add_package "1.2.3"
171
+ ::SocialSnippet::Repository::Models::Package.create(
172
+ :repo_name => "my-repo",
173
+ :rev_hash => "rev-1.2.3",
174
+ )
175
+ end
176
+ allow(fake_core.repo_manager).to receive(:install).with("git://driver.test/user/new-repo", nil, kind_of(::Hash)) do
177
+ repo = ::SocialSnippet::Repository::Models::Repository.find_or_create_by(:name => "new-repo")
178
+ pkg = ::SocialSnippet::Repository::Models::Package.new
179
+ pkg.add_dependency "my-repo", "1.2.3"
180
+ pkg
181
+ end
182
+ end
183
+
184
+ before { allow(fake_core.api).to receive(:install_repository).and_call_original }
185
+
186
+ context "run-command" do
187
+
188
+ before { install_command.run }
189
+ it { expect(fake_core.api).to have_received(:install_repository).with("git://driver.test/user/my-repo", "1.2.3", kind_of(::Hash)).once }
190
+ it { expect(fake_core.api).to have_received(:install_repository).with("git://driver.test/user/new-repo", nil, kind_of(::Hash)).once }
191
+
192
+ context "re-install new-repo" do
193
+ let(:re_install_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand.new ["new-repo"] }
194
+ before { re_install_command.init }
195
+ context "run-command" do
196
+ before { re_install_command.run }
197
+ it { expect(fake_core.api).to have_received(:install_repository).with("git://driver.test/user/my-repo", "1.2.3", kind_of(::Hash)).once }
198
+ it { expect(fake_core.api).to have_received(:install_repository).with("git://driver.test/user/new-repo", nil, kind_of(::Hash)).twice }
199
+ end
200
+ end
201
+
202
+ end
203
+
204
+ end # prepare stubs
205
+
206
+ end # prepare args
209
207
 
210
- subject { install_command_output.string }
211
- it { should match(/my-repo/) }
212
- it { should match(/new-repo/) }
213
- it { should match(/new-repo.*my-repo/m) }
214
- it { should match(/Installing: new-repo#1.2.4/) }
215
- it { should match(/Installing: my-repo#1.0.0/) }
216
- it { should match(/Cloning/) }
217
- it { should match(/Finding new-repo#1.2.4's/) }
218
- it { should match(/Success/) }
208
+ end # prepare registry info
219
209
 
220
- end # $ sspm install new-repo
210
+ end
221
211
 
222
- end # SSpm::SubCommands::InstallCommand
212
+ end # ::SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand
223
213
 
224
- end # SocialSnippet::CommandLine
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe ::SocialSnippet::CommandLine::SSpm::SubCommands::UpdateCommand do
4
+
5
+ describe "$ sspm update" do
6
+
7
+ before { allow(fake_core.api).to receive(:update_repository) }
8
+
9
+ context "prepare repositories" do
10
+
11
+ before do
12
+ ::SocialSnippet::Repository::Models::Repository.create(
13
+ :name => "repo-1",
14
+ :url => "url-repo-1",
15
+ )
16
+ end
17
+
18
+ before do
19
+ ::SocialSnippet::Repository::Models::Repository.create(
20
+ :name => "repo-2",
21
+ :url => "url-repo-2",
22
+ )
23
+ end
24
+
25
+ context "update all" do
26
+
27
+ let(:update_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::UpdateCommand.new [] }
28
+ before { update_command.init }
29
+
30
+ context "run command" do
31
+ before { update_command.run }
32
+ it { expect(fake_core.api).to have_received(:update_repository).with("repo-1", kind_of(::Hash)).once }
33
+ it { expect(fake_core.api).to have_received(:update_repository).with("repo-2", kind_of(::Hash)).once }
34
+ end
35
+
36
+ end # update all
37
+
38
+ context "update repo-1" do
39
+
40
+ let(:update_command) { ::SocialSnippet::CommandLine::SSpm::SubCommands::UpdateCommand.new ["repo-1"] }
41
+ before { update_command.init }
42
+
43
+ context "run command" do
44
+ before { update_command.run }
45
+ it { expect(fake_core.api).to have_received(:update_repository).with("repo-1", kind_of(::Hash)).once }
46
+ it { expect(fake_core.api).to_not have_received(:update_repository).with("repo-2", kind_of(::Hash)) }
47
+ end
48
+
49
+ end # update repo-1
50
+
51
+ end # prepare repositories
52
+
53
+ end # $ sspm update
54
+
55
+ end # ::SocialSnippet::CommandLine::SSpm::SubCommands::UpdateCommand
56
+
@@ -2,12 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS do
4
4
 
5
- let(:logger) do
6
- logger = ::SocialSnippet::Logger.new(STDOUT)
7
- logger.level = ::SocialSnippet::Logger::Severity::UNKNOWN
8
- logger
9
- end
10
-
11
5
  let(:social_snippet) do
12
6
  class Fake; end
13
7
  Fake.new
@@ -17,7 +11,11 @@ describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS do
17
11
  ::SocialSnippet::Config.new(social_snippet)
18
12
  end
19
13
 
20
- before { stub_const "ENV", "HOME" => Dir.mktmpdir }
14
+ before do
15
+ allow(social_snippet).to receive(:storage).and_return fake_storage
16
+ end
17
+
18
+ before { stub_const "ENV", "HOME" => ::Dir.mktmpdir }
21
19
 
22
20
  describe "sspm_url" do
23
21
 
@@ -106,7 +104,7 @@ describe SocialSnippet::Config, :without_fakefs => $WITHOUT_FAKEFS do
106
104
 
107
105
  context "set ENV[SOCIAL_SNIPPET_HOME]" do
108
106
 
109
- before { stub_const "ENV", "HOME" => Dir.mktmpdir, "SOCIAL_SNIPPET_HOME" => Dir.mktmpdir }
107
+ before { stub_const "ENV", "HOME" => ::Dir.mktmpdir, "SOCIAL_SNIPPET_HOME" => Dir.mktmpdir }
110
108
  it { expect(config.home).to_not eq ::File.join(ENV["HOME"], ".social-snippet") }
111
109
  it { expect(config.home).to eq ENV["SOCIAL_SNIPPET_HOME"] }
112
110
  it { expect(config.file_path).to eq ::File.join(ENV["SOCIAL_SNIPPET_HOME"], "config.json") }