social_snippet 0.0.1 → 0.0.2

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 (83) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +2 -0
  3. data/.travis.yml +22 -3
  4. data/Gemfile +25 -2
  5. data/Guardfile +9 -0
  6. data/README.md +6 -1
  7. data/Rakefile +51 -1
  8. data/appveyor.yml +36 -0
  9. data/bin/ssnip +10 -0
  10. data/bin/sspm +10 -0
  11. data/lib/social_snippet.rb +15 -4
  12. data/lib/social_snippet/api.rb +238 -0
  13. data/lib/social_snippet/command_line.rb +4 -0
  14. data/lib/social_snippet/command_line/command.rb +158 -0
  15. data/lib/social_snippet/command_line/ssnip.rb +2 -0
  16. data/lib/social_snippet/command_line/ssnip/main_command.rb +26 -0
  17. data/lib/social_snippet/command_line/sspm.rb +3 -0
  18. data/lib/social_snippet/command_line/sspm/main_command.rb +63 -0
  19. data/lib/social_snippet/command_line/sspm/sub_commands.rb +16 -0
  20. data/lib/social_snippet/command_line/sspm/sub_commands/complete_command.rb +28 -0
  21. data/lib/social_snippet/command_line/sspm/sub_commands/info_command.rb +28 -0
  22. data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +103 -0
  23. data/lib/social_snippet/command_line/sspm/sub_commands/publish_command.rb +51 -0
  24. data/lib/social_snippet/command_line/sspm/sub_commands/search_command.rb +32 -0
  25. data/lib/social_snippet/command_line/sspm/sub_commands/update_command.rb +37 -0
  26. data/lib/social_snippet/config.rb +92 -0
  27. data/lib/social_snippet/context.rb +89 -0
  28. data/lib/social_snippet/core.rb +40 -0
  29. data/lib/social_snippet/inserter.rb +64 -0
  30. data/lib/social_snippet/logger.rb +9 -0
  31. data/lib/social_snippet/registry.rb +3 -0
  32. data/lib/social_snippet/registry/registry_client.rb +15 -0
  33. data/lib/social_snippet/registry/registry_resources.rb +3 -0
  34. data/lib/social_snippet/registry/registry_resources/base.rb +80 -0
  35. data/lib/social_snippet/registry/registry_resources/repositories.rb +23 -0
  36. data/lib/social_snippet/repository.rb +6 -0
  37. data/lib/social_snippet/repository/drivers.rb +3 -0
  38. data/lib/social_snippet/repository/drivers/base_repository.rb +192 -0
  39. data/lib/social_snippet/repository/drivers/git_repository.rb +76 -0
  40. data/lib/social_snippet/repository/repository_errors.rb +5 -0
  41. data/lib/social_snippet/repository/repository_factory.rb +59 -0
  42. data/lib/social_snippet/repository/repository_installer.rb +86 -0
  43. data/lib/social_snippet/repository/repository_manager.rb +177 -0
  44. data/lib/social_snippet/resolvers.rb +4 -0
  45. data/lib/social_snippet/resolvers/base_resolver.rb +103 -0
  46. data/lib/social_snippet/resolvers/dep_resolver.rb +61 -0
  47. data/lib/social_snippet/resolvers/insert_resolver.rb +100 -0
  48. data/lib/social_snippet/snippet.rb +14 -0
  49. data/lib/social_snippet/tag.rb +198 -0
  50. data/lib/social_snippet/tag_parser.rb +61 -0
  51. data/lib/social_snippet/version.rb +26 -1
  52. data/social_snippet.gemspec +18 -3
  53. data/spec/helpers/codeclimate_helper.rb +4 -0
  54. data/spec/helpers/fakefs_helper.rb +15 -0
  55. data/spec/helpers/webmock_helper.rb +16 -0
  56. data/spec/lib/api_spec.rb +106 -0
  57. data/spec/lib/command_line/sspm_install_spec.rb +224 -0
  58. data/spec/lib/command_line/sspm_search_spec.rb +167 -0
  59. data/spec/lib/command_line/sspm_spec.rb +81 -0
  60. data/spec/lib/config_spec.rb +56 -0
  61. data/spec/lib/context_spec.rb +48 -0
  62. data/spec/lib/core_spec.rb +126 -0
  63. data/spec/lib/inserter_spec.rb +177 -0
  64. data/spec/lib/registry_client_spec.rb +173 -0
  65. data/spec/lib/repository/base_repository_spec.rb +104 -0
  66. data/spec/lib/repository/git_repository_spec.rb +83 -0
  67. data/spec/lib/repository/repository_factory_spec.rb +31 -0
  68. data/spec/lib/repository/repository_installer_spec.rb +63 -0
  69. data/spec/lib/repository/repository_manager_spec.rb +201 -0
  70. data/spec/lib/tag_parser_spec.rb +173 -0
  71. data/spec/lib/tag_spec.rb +93 -0
  72. data/spec/spec_helper.rb +106 -0
  73. data/test/base_repository_test.rb +375 -0
  74. data/test/command_test.rb +39 -0
  75. data/test/context_test.rb +31 -0
  76. data/test/core_test.rb +2091 -0
  77. data/test/git_repository_test.rb +114 -0
  78. data/test/install_command_test.rb +28 -0
  79. data/test/repository_manager_test.rb +109 -0
  80. data/test/tag_parser_test.rb +47 -0
  81. data/test/tag_test.rb +217 -0
  82. data/test/version_test.rb +56 -0
  83. metadata +271 -14
@@ -0,0 +1,224 @@
1
+ require "spec_helper"
2
+
3
+ module SocialSnippet::CommandLine
4
+
5
+ describe SSpm::SubCommands::InstallCommand do
6
+
7
+ 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"
12
+ end
13
+ end
14
+
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
+
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",
36
+ },
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
50
+
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
65
+
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
71
+
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
82
+
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
88
+
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
99
+
100
+ before do
101
+ allow(::FileUtils).to receive(:cp_r) do
102
+ # do nothing
103
+ end
104
+ end
105
+
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_social_snippet).to receive(:logger).and_return install_command_logger }
112
+
113
+ describe "$ sspm install" do
114
+
115
+ context "create snippet.json" do
116
+
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
126
+
127
+ example do
128
+ install_command = SSpm::SubCommands::InstallCommand.new([])
129
+ expect(fake_social_snippet.api).to receive(:install_repository_by_name).with("foo", "1.2.3", kind_of(Hash)).once
130
+ expect(fake_social_snippet.api).to receive(:install_repository_by_name).with("bar", "0.0.1", kind_of(Hash)).once
131
+ install_command.run
132
+ end
133
+
134
+ end # create snippet.json
135
+
136
+ end # $ sspm install
137
+
138
+ describe "$ sspm install my-repo" do
139
+
140
+ let(:install_command_output) { ::StringIO.new }
141
+ let(:install_command_logger) { ::SocialSnippet::Logger.new install_command_output }
142
+
143
+ before do
144
+ install_command_logger.level = ::SocialSnippet::Logger::Severity::INFO
145
+ allow(fake_social_snippet).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
149
+ end
150
+
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_social_snippet).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
170
+ end
171
+
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/) }
177
+
178
+ end # (reinstall) $ sspm install my-repo
179
+
180
+ end # $ sspm install my-repo
181
+
182
+ describe "$ sspm install new-repo" do
183
+
184
+ before do
185
+ install_command = SSpm::SubCommands::InstallCommand.new ["new-repo"]
186
+ install_command.init
187
+ install_command.run
188
+ end
189
+
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/) }
199
+
200
+ end # $ sspm install new-repo
201
+
202
+ describe "$ sspm install --dry-run new-repo" do
203
+
204
+ before do
205
+ install_command = SSpm::SubCommands::InstallCommand.new ["--dry-run", "new-repo"]
206
+ install_command.init
207
+ install_command.run
208
+ end
209
+
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/) }
219
+
220
+ end # $ sspm install new-repo
221
+
222
+ end # SSpm::SubCommands::InstallCommand
223
+
224
+ end # SocialSnippet::CommandLine
@@ -0,0 +1,167 @@
1
+ require "spec_helper"
2
+
3
+ module SocialSnippet::CommandLine
4
+
5
+ describe SSpm::SubCommands::SearchCommand do
6
+
7
+ let(:fake_repos) do
8
+ [
9
+ {
10
+ "name" => "my-repo",
11
+ "desc" => "This is my repository.",
12
+ "url" => "git://github.com/user/my-repo",
13
+ },
14
+ {
15
+ "name" => "new-repo",
16
+ "desc" => "This is new repository.",
17
+ "url" => "git://github.com/user/new-repo",
18
+ },
19
+ ]
20
+ end
21
+
22
+ before do
23
+ allow_any_instance_of(::SocialSnippet::Registry::RegistryResources::Base).to receive(:rest_client) do
24
+ RestClient::Resource.new "http://api.server/api/dummy"
25
+ end
26
+ end
27
+
28
+ context "create instance" do
29
+
30
+ let(:search_command_output) { ::StringIO.new }
31
+ let(:search_command_logger) { ::SocialSnippet::Logger.new search_command_output }
32
+ before { allow(fake_social_snippet).to receive(:logger).and_return search_command_logger }
33
+
34
+ describe "$ search repo" do
35
+
36
+ let(:search_command) { SSpm::SubCommands::SearchCommand.new(["repo"]) }
37
+ before { search_command.init }
38
+
39
+ before do
40
+ WebMock
41
+ .stub_request(
42
+ :get,
43
+ "http://api.server/api/dummy/repositories?q=repo",
44
+ )
45
+ .to_return(
46
+ :status => 200,
47
+ :body => fake_repos.to_json,
48
+ :headers => {
49
+ "Content-Type" => "application/json",
50
+ },
51
+ )
52
+ end # GET /repositories?q=repo
53
+
54
+ context "run" do
55
+
56
+ before { search_command.run }
57
+
58
+ context "name" do
59
+
60
+ it "my-repo" do
61
+ expect(search_command_output.string).to match(/my-repo/)
62
+ end
63
+
64
+ it "new-repo" do
65
+ expect(search_command_output.string).to match(/my-repo/)
66
+ end
67
+
68
+ end # name
69
+
70
+ context "desc" do
71
+
72
+ it "my-repo" do
73
+ expect(search_command_output.string).to match(/my repository/)
74
+ end
75
+
76
+ it "new-repo" do
77
+ expect(search_command_output.string).to match(/new repository/)
78
+ end
79
+
80
+ end # desc
81
+
82
+ context "url" do
83
+
84
+ it "my-repo" do
85
+ expect(search_command_output.string).to_not match(/#{"git://github.com/user/my-repo"}/)
86
+ end
87
+
88
+ it "new-repo" do
89
+ expect(search_command_output.string).to_not match(/#{"git://github.com/user/new-repo"}/)
90
+ end
91
+
92
+ end
93
+
94
+ end # run
95
+
96
+ end # $ search repo
97
+
98
+ describe "$ search --name --no-desc repo" do
99
+
100
+ let(:search_command) { SSpm::SubCommands::SearchCommand.new(["--name", "--no-desc", "repo"]) }
101
+ before { search_command.init }
102
+
103
+ before do
104
+ WebMock
105
+ .stub_request(
106
+ :get,
107
+ "http://api.server/api/dummy/repositories?q=repo",
108
+ )
109
+ .to_return(
110
+ :status => 200,
111
+ :body => fake_repos.to_json,
112
+ :headers => {
113
+ "Content-Type" => "application/json",
114
+ },
115
+ )
116
+ end # GET /repositories?q=repo
117
+
118
+ context "run" do
119
+
120
+ before { search_command.run }
121
+
122
+ context "name" do
123
+
124
+ it "my-repo" do
125
+ expect(search_command_output.string).to match(/my-repo/)
126
+ end
127
+
128
+ it "new-repo" do
129
+ expect(search_command_output.string).to match(/my-repo/)
130
+ end
131
+
132
+ end # name
133
+
134
+ context "no desc" do
135
+
136
+ it "my-repo" do
137
+ expect(search_command_output.string).to_not match(/my repository/)
138
+ end
139
+
140
+ it "new-repo" do
141
+ expect(search_command_output.string).to_not match(/new repository/)
142
+ end
143
+
144
+ end # desc
145
+
146
+ context "no url" do
147
+
148
+ it "my-repo" do
149
+ expect(search_command_output.string).to_not match(/#{"git://github.com/user/my-repo"}/)
150
+ end
151
+
152
+ it "new-repo" do
153
+ expect(search_command_output.string).to_not match(/#{"git://github.com/user/new-repo"}/)
154
+ end
155
+
156
+ end
157
+
158
+ end # run
159
+
160
+ end # $ search --name repo
161
+
162
+ end # create instance
163
+
164
+ end # SSpm::SubCommands::SearchCommand
165
+
166
+ end # SocialSnippet::CommandLine::Sspm
167
+
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+
3
+ module SocialSnippet::CommandLine
4
+
5
+ describe SSpm::MainCommand do
6
+
7
+ describe "$ sspm search repo" do
8
+
9
+ let(:sspm_command) { SSpm::MainCommand.new ["search", "repo"] }
10
+
11
+ example do
12
+ expect(sspm_command).to receive(:call_subcommand).with(:SearchCommand).once
13
+ sspm_command.init
14
+ sspm_command.run
15
+ end
16
+
17
+ end
18
+
19
+ describe "$ sspm complete" do
20
+
21
+ let(:sspm_command) { SSpm::MainCommand.new ["complete", "// @snip <repo"] }
22
+
23
+ example do
24
+ expect(sspm_command).to receive(:call_subcommand).with(:CompleteCommand).once
25
+ sspm_command.init
26
+ sspm_command.run
27
+ end
28
+
29
+ end
30
+
31
+ describe "$ sspm install my-repo" do
32
+
33
+ let(:sspm_command) { SSpm::MainCommand.new ["install", "my-repo"] }
34
+
35
+ example do
36
+ expect(sspm_command).to receive(:call_subcommand).with(:InstallCommand).once
37
+ sspm_command.init
38
+ sspm_command.run
39
+ end
40
+
41
+ end
42
+
43
+ describe "$ sspm update" do
44
+
45
+ let(:sspm_command) { SSpm::MainCommand.new ["update"] }
46
+
47
+ example do
48
+ expect(sspm_command).to receive(:call_subcommand).with(:UpdateCommand).once
49
+ sspm_command.init
50
+ sspm_command.run
51
+ end
52
+
53
+ end
54
+
55
+ describe "$ sspm publish {url}" do
56
+
57
+ let(:sspm_command) { SSpm::MainCommand.new ["publish", "https://github.com/user/repo"] }
58
+
59
+ example do
60
+ expect(sspm_command).to receive(:call_subcommand).with(:PublishCommand).once
61
+ sspm_command.init
62
+ sspm_command.run
63
+ end
64
+
65
+ end
66
+
67
+ describe "$ sspm info {repo-name}" do
68
+
69
+ let(:sspm_command) { SSpm::MainCommand.new ["info", "my-repo"] }
70
+
71
+ example do
72
+ expect(sspm_command).to receive(:call_subcommand).with(:InfoCommand).once
73
+ sspm_command.init
74
+ sspm_command.run
75
+ end
76
+
77
+ end
78
+
79
+ end # SSpm::MainCommand
80
+
81
+ end # SocialSnippet::CommandLine