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.
- checksums.yaml +8 -8
- data/.gitignore +2 -0
- data/.travis.yml +22 -3
- data/Gemfile +25 -2
- data/Guardfile +9 -0
- data/README.md +6 -1
- data/Rakefile +51 -1
- data/appveyor.yml +36 -0
- data/bin/ssnip +10 -0
- data/bin/sspm +10 -0
- data/lib/social_snippet.rb +15 -4
- data/lib/social_snippet/api.rb +238 -0
- data/lib/social_snippet/command_line.rb +4 -0
- data/lib/social_snippet/command_line/command.rb +158 -0
- data/lib/social_snippet/command_line/ssnip.rb +2 -0
- data/lib/social_snippet/command_line/ssnip/main_command.rb +26 -0
- data/lib/social_snippet/command_line/sspm.rb +3 -0
- data/lib/social_snippet/command_line/sspm/main_command.rb +63 -0
- data/lib/social_snippet/command_line/sspm/sub_commands.rb +16 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/complete_command.rb +28 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/info_command.rb +28 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +103 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/publish_command.rb +51 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/search_command.rb +32 -0
- data/lib/social_snippet/command_line/sspm/sub_commands/update_command.rb +37 -0
- data/lib/social_snippet/config.rb +92 -0
- data/lib/social_snippet/context.rb +89 -0
- data/lib/social_snippet/core.rb +40 -0
- data/lib/social_snippet/inserter.rb +64 -0
- data/lib/social_snippet/logger.rb +9 -0
- data/lib/social_snippet/registry.rb +3 -0
- data/lib/social_snippet/registry/registry_client.rb +15 -0
- data/lib/social_snippet/registry/registry_resources.rb +3 -0
- data/lib/social_snippet/registry/registry_resources/base.rb +80 -0
- data/lib/social_snippet/registry/registry_resources/repositories.rb +23 -0
- data/lib/social_snippet/repository.rb +6 -0
- data/lib/social_snippet/repository/drivers.rb +3 -0
- data/lib/social_snippet/repository/drivers/base_repository.rb +192 -0
- data/lib/social_snippet/repository/drivers/git_repository.rb +76 -0
- data/lib/social_snippet/repository/repository_errors.rb +5 -0
- data/lib/social_snippet/repository/repository_factory.rb +59 -0
- data/lib/social_snippet/repository/repository_installer.rb +86 -0
- data/lib/social_snippet/repository/repository_manager.rb +177 -0
- data/lib/social_snippet/resolvers.rb +4 -0
- data/lib/social_snippet/resolvers/base_resolver.rb +103 -0
- data/lib/social_snippet/resolvers/dep_resolver.rb +61 -0
- data/lib/social_snippet/resolvers/insert_resolver.rb +100 -0
- data/lib/social_snippet/snippet.rb +14 -0
- data/lib/social_snippet/tag.rb +198 -0
- data/lib/social_snippet/tag_parser.rb +61 -0
- data/lib/social_snippet/version.rb +26 -1
- data/social_snippet.gemspec +18 -3
- data/spec/helpers/codeclimate_helper.rb +4 -0
- data/spec/helpers/fakefs_helper.rb +15 -0
- data/spec/helpers/webmock_helper.rb +16 -0
- data/spec/lib/api_spec.rb +106 -0
- data/spec/lib/command_line/sspm_install_spec.rb +224 -0
- data/spec/lib/command_line/sspm_search_spec.rb +167 -0
- data/spec/lib/command_line/sspm_spec.rb +81 -0
- data/spec/lib/config_spec.rb +56 -0
- data/spec/lib/context_spec.rb +48 -0
- data/spec/lib/core_spec.rb +126 -0
- data/spec/lib/inserter_spec.rb +177 -0
- data/spec/lib/registry_client_spec.rb +173 -0
- data/spec/lib/repository/base_repository_spec.rb +104 -0
- data/spec/lib/repository/git_repository_spec.rb +83 -0
- data/spec/lib/repository/repository_factory_spec.rb +31 -0
- data/spec/lib/repository/repository_installer_spec.rb +63 -0
- data/spec/lib/repository/repository_manager_spec.rb +201 -0
- data/spec/lib/tag_parser_spec.rb +173 -0
- data/spec/lib/tag_spec.rb +93 -0
- data/spec/spec_helper.rb +106 -0
- data/test/base_repository_test.rb +375 -0
- data/test/command_test.rb +39 -0
- data/test/context_test.rb +31 -0
- data/test/core_test.rb +2091 -0
- data/test/git_repository_test.rb +114 -0
- data/test/install_command_test.rb +28 -0
- data/test/repository_manager_test.rb +109 -0
- data/test/tag_parser_test.rb +47 -0
- data/test/tag_test.rb +217 -0
- data/test/version_test.rb +56 -0
- metadata +271 -14
@@ -0,0 +1,173 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SocialSnippet::TagParser do
|
4
|
+
|
5
|
+
describe "#find_snip_tags" do
|
6
|
+
|
7
|
+
context "no @snip tags" do
|
8
|
+
|
9
|
+
let(:input_text) do
|
10
|
+
[
|
11
|
+
'input text',
|
12
|
+
].join($/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns an empty array" do
|
16
|
+
expect(SocialSnippet::TagParser.find_snip_tags(input_text)).to eq []
|
17
|
+
end
|
18
|
+
|
19
|
+
end # no snip tags
|
20
|
+
|
21
|
+
context "single @snip tag" do
|
22
|
+
|
23
|
+
let(:input_text) do
|
24
|
+
[
|
25
|
+
'#include <stdio.h>',
|
26
|
+
'',
|
27
|
+
'// @snip <path/to/file.c>',
|
28
|
+
'',
|
29
|
+
'int main() {',
|
30
|
+
' func();',
|
31
|
+
' return 0;',
|
32
|
+
'}',
|
33
|
+
].join($/)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "result" do
|
37
|
+
|
38
|
+
let(:result) { SocialSnippet::TagParser.find_snip_tags(input_text) }
|
39
|
+
|
40
|
+
it "has one element" do
|
41
|
+
expect(result.length).to eq 1
|
42
|
+
end
|
43
|
+
|
44
|
+
context "line_no" do
|
45
|
+
it { expect(result[0][:line_no]).to eq 2 }
|
46
|
+
end
|
47
|
+
|
48
|
+
context "tag.to_snippet_tag" do
|
49
|
+
it { expect(result[0][:tag].to_snippet_tag).to eq "// @snippet <path/to/file.c>" }
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end # a snip tag
|
55
|
+
|
56
|
+
context "multi @snip tags" do
|
57
|
+
|
58
|
+
let(:input_text) do
|
59
|
+
[
|
60
|
+
'#include <stdio.h>',
|
61
|
+
'',
|
62
|
+
'// @snip <path/to/file1.c>',
|
63
|
+
'// @snip <./path/to/file2.c>',
|
64
|
+
'',
|
65
|
+
'int main() {',
|
66
|
+
' func();',
|
67
|
+
' return 0;',
|
68
|
+
'}',
|
69
|
+
].join($/)
|
70
|
+
end
|
71
|
+
|
72
|
+
context "result" do
|
73
|
+
|
74
|
+
let(:result) { SocialSnippet::TagParser.find_snip_tags(input_text) }
|
75
|
+
|
76
|
+
it "has two elements" do
|
77
|
+
expect(result.length).to eq 2
|
78
|
+
end
|
79
|
+
|
80
|
+
context "line_no" do
|
81
|
+
it { expect(result[0][:line_no]).to eq 2 }
|
82
|
+
it { expect(result[1][:line_no]).to eq 3 }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "tag.to_snippet_tag" do
|
86
|
+
it { expect(result[0][:tag].to_snippet_tag).to eq "// @snippet <path/to/file1.c>" }
|
87
|
+
it { expect(result[1][:tag].to_snippet_tag).to eq "// @snippet <path/to/file2.c>"}
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end # multi snip tags
|
93
|
+
|
94
|
+
context "@snip tags with repository" do
|
95
|
+
|
96
|
+
let(:input_text) do
|
97
|
+
[
|
98
|
+
'# use repository',
|
99
|
+
'# @snip <repo-a:path/to/file1.rb>',
|
100
|
+
'# @snip <repo-b:path/to/file1.rb>',
|
101
|
+
'# @snip <repo-b:/path/to/file2.rb>',
|
102
|
+
'# @snippet <path/to/file3.rb>',
|
103
|
+
'',
|
104
|
+
'puts "hello"',
|
105
|
+
].join($/)
|
106
|
+
end
|
107
|
+
|
108
|
+
context "result" do
|
109
|
+
|
110
|
+
let(:result) { SocialSnippet::TagParser.find_snip_tags(input_text) }
|
111
|
+
|
112
|
+
it "has three elements" do
|
113
|
+
expect(result.length).to eq 3
|
114
|
+
end
|
115
|
+
|
116
|
+
context "line_no" do
|
117
|
+
it { expect(result[0][:line_no]).to eq 1 }
|
118
|
+
it { expect(result[1][:line_no]).to eq 2 }
|
119
|
+
it { expect(result[2][:line_no]).to eq 3 }
|
120
|
+
end
|
121
|
+
|
122
|
+
context "tag.to_snippet_tag" do
|
123
|
+
it { expect(result[0][:tag].to_snippet_tag).to eq "# @snippet <repo-a:path/to/file1.rb>" }
|
124
|
+
it { expect(result[1][:tag].to_snippet_tag).to eq "# @snippet <repo-b:path/to/file1.rb>" }
|
125
|
+
it { expect(result[2][:tag].to_snippet_tag).to eq "# @snippet <repo-b:path/to/file2.rb>" }
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end # find_snip_tags
|
133
|
+
|
134
|
+
describe "#find_snippet_tags" do
|
135
|
+
|
136
|
+
context "@snip tags with repository" do
|
137
|
+
|
138
|
+
let(:input_text) do
|
139
|
+
[
|
140
|
+
'# use repository',
|
141
|
+
'# @snip <repo-a:path/to/file1.rb>',
|
142
|
+
'# @snip <repo-b:path/to/file1.rb>',
|
143
|
+
'# @snip <repo-b:/path/to/file2.rb>',
|
144
|
+
'# @snippet <path/to/file3.rb>',
|
145
|
+
'',
|
146
|
+
'puts "hello"',
|
147
|
+
].join($/)
|
148
|
+
end
|
149
|
+
|
150
|
+
context "result" do
|
151
|
+
|
152
|
+
let(:result) { SocialSnippet::TagParser.find_snippet_tags(input_text) }
|
153
|
+
|
154
|
+
it "has one element" do
|
155
|
+
expect(result.length).to eq 1
|
156
|
+
end
|
157
|
+
|
158
|
+
context "line_no" do
|
159
|
+
it { expect(result[0][:line_no]).to eq 4 }
|
160
|
+
end
|
161
|
+
|
162
|
+
context "tag.to_snip_tag" do
|
163
|
+
it { expect(result[0][:tag].to_snip_tag).to eq "# @snip <path/to/file3.rb>" }
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
end # snip tags with repository
|
169
|
+
|
170
|
+
end # find_snippet_tags
|
171
|
+
|
172
|
+
end # SocialSnippet::TagParser
|
173
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SocialSnippet::Tag do
|
4
|
+
|
5
|
+
describe ".new" do
|
6
|
+
|
7
|
+
context "// @snip <path/to/file.cxx>" do
|
8
|
+
|
9
|
+
let(:instance) { SocialSnippet::Tag.new("// @snip <path/to/file.cxx>") }
|
10
|
+
|
11
|
+
context "to_snippet_tag" do
|
12
|
+
subject { instance.to_snippet_tag }
|
13
|
+
it { should eq "// @snippet <path/to/file.cxx>" }
|
14
|
+
end
|
15
|
+
|
16
|
+
end # snip <path/to/file.cxx>
|
17
|
+
|
18
|
+
context "/* @snip <path/to/file.c> */" do
|
19
|
+
|
20
|
+
let(:instance) { SocialSnippet::Tag.new("/* @snip <path/to/file.c> */") }
|
21
|
+
|
22
|
+
context "to_snippet_tag" do
|
23
|
+
subject { instance.to_snippet_tag }
|
24
|
+
it { should eq "/* @snippet <path/to/file.c> */" }
|
25
|
+
end
|
26
|
+
|
27
|
+
end # snip <path/to/file.c>
|
28
|
+
|
29
|
+
context "# @snippet <many/spaces.py>" do
|
30
|
+
|
31
|
+
let(:instance) { SocialSnippet::Tag.new("# @snippet <many/space.py>") }
|
32
|
+
|
33
|
+
context "to_snip_tag" do
|
34
|
+
subject { instance.to_snip_tag }
|
35
|
+
it { should eq "# @snip <many/space.py>" }
|
36
|
+
end
|
37
|
+
|
38
|
+
end # snippet <many/spaces.py>
|
39
|
+
|
40
|
+
context "// @snip <repo:use/repo.cpp>" do
|
41
|
+
|
42
|
+
let(:instance) { SocialSnippet::Tag.new("// @snip <repo:use/repo.cpp>") }
|
43
|
+
|
44
|
+
context "to_snippet_tag" do
|
45
|
+
subject { instance.to_snippet_tag }
|
46
|
+
it { should eq "// @snippet <repo:use/repo.cpp>" }
|
47
|
+
end
|
48
|
+
|
49
|
+
end # snip <repo:use/repo.cpp>
|
50
|
+
|
51
|
+
context '// @snip <repo#ref:use/repo/and/version.cpp' do
|
52
|
+
|
53
|
+
let(:instance) { SocialSnippet::Tag.new('// @snip <repo#ref:use/repo/and/version.cpp>') }
|
54
|
+
it { expect(instance.repo).to eq "repo" }
|
55
|
+
it { expect(instance.ref).to eq "ref" }
|
56
|
+
|
57
|
+
context "to_snippet_tag" do
|
58
|
+
subject { instance.to_snippet_tag }
|
59
|
+
it { should eq "// @snippet <repo#ref:use/repo/and/version.cpp>" }
|
60
|
+
end
|
61
|
+
|
62
|
+
end # snip <repo#ref:use/repo/and/version.cpp
|
63
|
+
|
64
|
+
context '# @snip <repo#ref:use/repo/and/version.rb' do
|
65
|
+
|
66
|
+
let(:instance) { SocialSnippet::Tag.new('# @snip <repo#ref:use/repo/and/version.rb>') }
|
67
|
+
it { expect(instance.repo).to eq "repo" }
|
68
|
+
it { expect(instance.ref).to eq "ref" }
|
69
|
+
|
70
|
+
context "to_snippet_tag" do
|
71
|
+
subject { instance.to_snippet_tag }
|
72
|
+
it { should eq "# @snippet <repo#ref:use/repo/and/version.rb>" }
|
73
|
+
end
|
74
|
+
|
75
|
+
end # snip <repo#ref:use/repo/and/version.rb
|
76
|
+
|
77
|
+
context '# @snip <repo#ref:use/repo/and/version.rb #' do
|
78
|
+
|
79
|
+
let(:instance) { SocialSnippet::Tag.new('# @snip <repo#ref:use/repo/and/version.rb> #') }
|
80
|
+
it { expect(instance.repo).to eq "repo" }
|
81
|
+
it { expect(instance.ref).to eq "ref" }
|
82
|
+
|
83
|
+
context "to_snippet_tag" do
|
84
|
+
subject { instance.to_snippet_tag }
|
85
|
+
it { should eq "# @snippet <repo#ref:use/repo/and/version.rb> #" }
|
86
|
+
end
|
87
|
+
|
88
|
+
end # snip <repo#ref:use/repo/and/version.rb
|
89
|
+
|
90
|
+
end # .new
|
91
|
+
|
92
|
+
end
|
93
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,106 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require_relative "helpers/codeclimate_helper"
|
3
|
+
require_relative "helpers/webmock_helper"
|
4
|
+
|
5
|
+
require "social_snippet"
|
6
|
+
require "json"
|
7
|
+
require "cgi"
|
8
|
+
require "stringio"
|
9
|
+
|
10
|
+
require_relative "helpers/fakefs_helper"
|
11
|
+
|
12
|
+
module SocialSnippet::SpecHelpers
|
13
|
+
|
14
|
+
class Fake; end
|
15
|
+
|
16
|
+
def fake_io
|
17
|
+
@fake_io ||= StringIO.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def fake_logger
|
21
|
+
reset_fake_logger unless @logger
|
22
|
+
@logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset_fake_logger
|
26
|
+
@logger = ::SocialSnippet::Logger.new(fake_io)
|
27
|
+
@logger.level = ::SocialSnippet::Logger::Severity::INFO
|
28
|
+
end
|
29
|
+
|
30
|
+
def fake_home
|
31
|
+
reset_fake_home unless @tmp_path
|
32
|
+
@tmp_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def reset_fake_home
|
36
|
+
tmp_root = File.join(Dir.tmpdir, "social_snippet")
|
37
|
+
FileUtils.mkdir_p tmp_root
|
38
|
+
@tmp_path = Dir.mktmpdir(nil, tmp_root)
|
39
|
+
end
|
40
|
+
|
41
|
+
def make_fake_home
|
42
|
+
fake_config.init_directories
|
43
|
+
end
|
44
|
+
|
45
|
+
def global_config
|
46
|
+
$social_snippet_config ||= ::SocialSnippet::Config.new(
|
47
|
+
fake_social_snippet,
|
48
|
+
{
|
49
|
+
:home => fake_home,
|
50
|
+
:sspm_host => "api.server",
|
51
|
+
},
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def enable_global_config
|
56
|
+
@enable_global_config = true
|
57
|
+
end
|
58
|
+
|
59
|
+
def fake_config
|
60
|
+
@config ||= ::SocialSnippet::Config.new(
|
61
|
+
fake_social_snippet,
|
62
|
+
{
|
63
|
+
:home => fake_home,
|
64
|
+
:sspm_host => "api.server",
|
65
|
+
},
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def fake_api
|
70
|
+
@fake_api ||= ::SocialSnippet::Api.new(fake_social_snippet)
|
71
|
+
end
|
72
|
+
|
73
|
+
def fake_social_snippet
|
74
|
+
reset_fake_social_snippet unless @fake_social_snippet
|
75
|
+
@fake_social_snippet
|
76
|
+
end
|
77
|
+
|
78
|
+
def reset_fake_social_snippet
|
79
|
+
@fake_social_snippet = Fake.new
|
80
|
+
allow(fake_social_snippet).to receive(:logger).and_return fake_logger
|
81
|
+
allow(fake_social_snippet).to receive(:config).and_return fake_config
|
82
|
+
allow(fake_social_snippet).to receive(:api).and_return fake_api
|
83
|
+
allow(fake_social_snippet).to receive(:repo_manager).and_return ::SocialSnippet::Repository::RepositoryManager.new(fake_social_snippet)
|
84
|
+
allow(fake_social_snippet).to receive(:registry_client).and_return ::SocialSnippet::Registry::RegistryClient.new(fake_social_snippet)
|
85
|
+
allow_any_instance_of(::SocialSnippet::CommandLine::Command).to receive(:social_snippet).and_return fake_social_snippet
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
module SocialSnippet
|
91
|
+
::RSpec.configure do |config|
|
92
|
+
config.include FakeFSHelpers
|
93
|
+
config.before { enable_fakefs }
|
94
|
+
config.after { disable_fakefs }
|
95
|
+
|
96
|
+
config.include SpecHelpers
|
97
|
+
config.before { reset_fake_social_snippet }
|
98
|
+
|
99
|
+
config.before(:example, :without_fakefs => true) do
|
100
|
+
disable_fakefs
|
101
|
+
make_fake_home
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
$WITHOUT_FAKEFS = (ENV["RSPEC_WITHOUT_FAKEFS"] === "true")
|
@@ -0,0 +1,375 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module SocialSnippet::Repository::Drivers
|
4
|
+
|
5
|
+
describe BaseRepository do
|
6
|
+
|
7
|
+
describe "version" do
|
8
|
+
|
9
|
+
context "new path/to/repo" do
|
10
|
+
|
11
|
+
let(:repo) { BaseRepository.new('/path/to/repo') }
|
12
|
+
|
13
|
+
context "version only cases" do
|
14
|
+
|
15
|
+
context "has 0.0.1" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow(repo).to receive(:refs).and_return([
|
19
|
+
'0.0.1',
|
20
|
+
])
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "versions" do
|
24
|
+
let(:result) { repo.versions }
|
25
|
+
it { expect(result.length).to eq 1 }
|
26
|
+
it { expect(result).to include '0.0.1' }
|
27
|
+
end # versions
|
28
|
+
|
29
|
+
describe "latest_version" do
|
30
|
+
it { expect(repo.latest_version).to eq '0.0.1' }
|
31
|
+
it { expect(repo.latest_version('0')).to eq '0.0.1' }
|
32
|
+
it { expect(repo.latest_version('0.0')).to eq '0.0.1' }
|
33
|
+
it { expect(repo.latest_version('0.0.1')).to eq '0.0.1' }
|
34
|
+
it { expect(repo.latest_version('1.0')).to be_nil }
|
35
|
+
end # latest_version
|
36
|
+
|
37
|
+
end # has 0.0.1
|
38
|
+
|
39
|
+
context "has 0.0.1, 0.0.2, 0.0.3, 1.0.0" do
|
40
|
+
|
41
|
+
before do
|
42
|
+
allow(repo).to receive(:refs).and_return([
|
43
|
+
'0.0.1',
|
44
|
+
'0.0.2',
|
45
|
+
'0.0.3',
|
46
|
+
'1.0.0',
|
47
|
+
])
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "versions" do
|
51
|
+
|
52
|
+
let(:result) { repo.versions }
|
53
|
+
|
54
|
+
it { expect(result.length).to eq 4 }
|
55
|
+
|
56
|
+
context "check result" do
|
57
|
+
subject { result }
|
58
|
+
it { should include '0.0.1' }
|
59
|
+
it { should include '0.0.2' }
|
60
|
+
it { should include '0.0.3' }
|
61
|
+
it { should include '1.0.0' }
|
62
|
+
end
|
63
|
+
|
64
|
+
end # versions
|
65
|
+
|
66
|
+
describe "latest_version" do
|
67
|
+
it { expect(repo.latest_version).to eq '1.0.0' }
|
68
|
+
it { expect(repo.latest_version('0')).to eq '0.0.3' }
|
69
|
+
it { expect(repo.latest_version('0.0')).to eq '0.0.3' }
|
70
|
+
it { expect(repo.latest_version('1')).to eq '1.0.0' }
|
71
|
+
it { expect(repo.latest_version('0.1')).to be_nil }
|
72
|
+
end # latest_version
|
73
|
+
|
74
|
+
end # has 0.0.1, 0.0.2, 0.0.3, 1.0.0
|
75
|
+
|
76
|
+
context "has 1.2.3, 100.2.300, 123.456.789" do
|
77
|
+
|
78
|
+
before do
|
79
|
+
allow(repo).to receive(:refs).and_return([
|
80
|
+
'1.2.3',
|
81
|
+
'100.2.300',
|
82
|
+
'123.456.789',
|
83
|
+
])
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "versions" do
|
87
|
+
|
88
|
+
let(:result) { repo.versions }
|
89
|
+
|
90
|
+
it { expect(result.length).to eq 3 }
|
91
|
+
|
92
|
+
context "check result" do
|
93
|
+
subject { result }
|
94
|
+
it { should include '1.2.3' }
|
95
|
+
it { should include '100.2.300' }
|
96
|
+
it { should include '123.456.789' }
|
97
|
+
end
|
98
|
+
|
99
|
+
end # versions
|
100
|
+
|
101
|
+
describe "latest_version" do
|
102
|
+
it { expect(repo.latest_version).to eq '123.456.789' }
|
103
|
+
it { expect(repo.latest_version('0')).to be_nil }
|
104
|
+
it { expect(repo.latest_version('0.0')).to be_nil }
|
105
|
+
it { expect(repo.latest_version('1')).to eq '1.2.3' }
|
106
|
+
it { expect(repo.latest_version('100')).to eq '100.2.300' }
|
107
|
+
it { expect(repo.latest_version('100.2')).to eq '100.2.300' }
|
108
|
+
it { expect(repo.latest_version('123')).to eq '123.456.789' }
|
109
|
+
it { expect(repo.latest_version('123.456')).to eq '123.456.789' }
|
110
|
+
end # latest_version
|
111
|
+
|
112
|
+
end # has 1.2.3, 100.2.300, 123.456.789
|
113
|
+
|
114
|
+
end # version only cases
|
115
|
+
|
116
|
+
context "include not version cases" do
|
117
|
+
|
118
|
+
context "has master, develop, 0.0.1, 0.1.0, 1.0.0" do
|
119
|
+
|
120
|
+
before do
|
121
|
+
allow(repo).to receive(:refs).and_return([
|
122
|
+
'master',
|
123
|
+
'develop',
|
124
|
+
'0.0.1',
|
125
|
+
'0.1.0',
|
126
|
+
'1.0.0',
|
127
|
+
])
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "versions" do
|
131
|
+
let(:result) { repo.versions }
|
132
|
+
|
133
|
+
it { expect(result.length).to eq 3 }
|
134
|
+
|
135
|
+
context "check result" do
|
136
|
+
subject { result }
|
137
|
+
it { should include '0.0.1' }
|
138
|
+
it { should include '0.1.0' }
|
139
|
+
it { should include '1.0.0' }
|
140
|
+
end
|
141
|
+
end # versions
|
142
|
+
|
143
|
+
describe "latest_version" do
|
144
|
+
it { expect(repo.latest_version).to eq '1.0.0' }
|
145
|
+
it { expect(repo.latest_version('0')).to eq '0.1.0' }
|
146
|
+
it { expect(repo.latest_version('0.0')).to eq '0.0.1' }
|
147
|
+
it { expect(repo.latest_version('1')).to eq '1.0.0' }
|
148
|
+
it { expect(repo.latest_version('100')).to be_nil }
|
149
|
+
it { expect(repo.latest_version('100.2')).to be_nil }
|
150
|
+
it { expect(repo.latest_version('123')).to be_nil}
|
151
|
+
it { expect(repo.latest_version('123.456')).to be_nil }
|
152
|
+
it { expect(repo.latest_version('master')).to be_nil }
|
153
|
+
it { expect(repo.latest_version('develop')).to be_nil }
|
154
|
+
end # latest_version
|
155
|
+
|
156
|
+
end # has master, develop, 0.0.1, 0.1.0, 1.0.0
|
157
|
+
|
158
|
+
context "has master, feature/0.0.1, 0.0.1/test, 001, 0.0, 1, 1.2.3" do
|
159
|
+
|
160
|
+
before do
|
161
|
+
allow(repo).to receive(:refs).and_return([
|
162
|
+
'master',
|
163
|
+
'feature/0.0.1',
|
164
|
+
'0.0.1/test',
|
165
|
+
'001',
|
166
|
+
'0.0',
|
167
|
+
'1',
|
168
|
+
'1.2.3',
|
169
|
+
])
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "versions" do
|
173
|
+
|
174
|
+
let(:result) { repo.versions }
|
175
|
+
|
176
|
+
it { expect(result.length).to eq 1 }
|
177
|
+
it { expect(result).to include '1.2.3' }
|
178
|
+
|
179
|
+
end # versions
|
180
|
+
|
181
|
+
describe "latest_version" do
|
182
|
+
it { expect(repo.latest_version).to eq '1.2.3' }
|
183
|
+
it { expect(repo.latest_version('0')).to be_nil }
|
184
|
+
it { expect(repo.latest_version('0.0')).to be_nil }
|
185
|
+
it { expect(repo.latest_version('1')).to eq '1.2.3' }
|
186
|
+
it { expect(repo.latest_version('100')).to be_nil }
|
187
|
+
it { expect(repo.latest_version('100.2')).to be_nil }
|
188
|
+
it { expect(repo.latest_version('123')).to be_nil}
|
189
|
+
it { expect(repo.latest_version('123.456')).to be_nil }
|
190
|
+
it { expect(repo.latest_version('master')).to be_nil }
|
191
|
+
it { expect(repo.latest_version('develop')).to be_nil }
|
192
|
+
end # latest_version
|
193
|
+
|
194
|
+
end # has master, feature/0.0.1, 0.0.1/test, 001, 0.0, 1, 1.2.3
|
195
|
+
|
196
|
+
end # include not version cases
|
197
|
+
|
198
|
+
end # new path/to/repo
|
199
|
+
|
200
|
+
end # versions
|
201
|
+
|
202
|
+
describe "cache test" do
|
203
|
+
|
204
|
+
let(:commit_id) { "thisisdummyyyyy" }
|
205
|
+
|
206
|
+
context "there is a repo" do
|
207
|
+
|
208
|
+
before do
|
209
|
+
FileUtils.mkdir_p "/path/to/repo_1"
|
210
|
+
FileUtils.mkdir_p "/path/to/repo_1/.git"
|
211
|
+
FileUtils.touch "/path/to/repo_1/snippet.json"
|
212
|
+
|
213
|
+
File.write "/path/to/repo_1/snippet.json", [
|
214
|
+
'{',
|
215
|
+
' "name": "repo_1",',
|
216
|
+
' "desc": "this is repo_1",',
|
217
|
+
' "language": "Ruby"',
|
218
|
+
'}',
|
219
|
+
].join("\n")
|
220
|
+
end
|
221
|
+
|
222
|
+
context "create repo_1 instance" do
|
223
|
+
|
224
|
+
let(:cache_path) { "/path/to/cache" }
|
225
|
+
before { FileUtils.mkdir_p(cache_path) }
|
226
|
+
|
227
|
+
let(:instance) do
|
228
|
+
repo = BaseRepository.new("/path/to/repo_1")
|
229
|
+
repo.load_snippet_json
|
230
|
+
return repo
|
231
|
+
end
|
232
|
+
|
233
|
+
context "name" do
|
234
|
+
subject { instance.name }
|
235
|
+
it { should eq "repo_1" }
|
236
|
+
end
|
237
|
+
|
238
|
+
context "create cache" do
|
239
|
+
before do
|
240
|
+
expect(instance).to receive(:commit_id).and_return commit_id
|
241
|
+
instance.create_cache(cache_path)
|
242
|
+
end
|
243
|
+
|
244
|
+
context "snippet.json" do
|
245
|
+
let(:result) { JSON.parse File.read "#{cache_path}/repo_1/#{commit_id[0..7]}/snippet.json" }
|
246
|
+
it { expect(result["name"]).to eq "repo_1" }
|
247
|
+
it { expect(result["desc"]).to eq "this is repo_1" }
|
248
|
+
it { expect(result["language"]).to eq "Ruby" }
|
249
|
+
end
|
250
|
+
|
251
|
+
end # create cache
|
252
|
+
|
253
|
+
end # create repo_1 instance
|
254
|
+
|
255
|
+
end # there is a repo
|
256
|
+
|
257
|
+
context "there are three repos" do
|
258
|
+
|
259
|
+
before do
|
260
|
+
# create repo_1
|
261
|
+
FileUtils.mkdir_p "/path/to/repo_1"
|
262
|
+
FileUtils.mkdir_p "/path/to/repo_1/.git"
|
263
|
+
FileUtils.touch "/path/to/repo_1/snippet.json"
|
264
|
+
File.write "/path/to/repo_1/snippet.json", [
|
265
|
+
'{',
|
266
|
+
' "name": "repo_1",',
|
267
|
+
' "desc": "this is repo_1",',
|
268
|
+
' "language": "Ruby"',
|
269
|
+
'}',
|
270
|
+
].join("\n")
|
271
|
+
|
272
|
+
# create repo_b
|
273
|
+
FileUtils.mkdir_p "/path/to/repo_b"
|
274
|
+
FileUtils.mkdir_p "/path/to/repo_b/.git"
|
275
|
+
FileUtils.touch "/path/to/repo_b/snippet.json"
|
276
|
+
File.write "/path/to/repo_b/snippet.json", [
|
277
|
+
'{',
|
278
|
+
' "name": "repo_b",',
|
279
|
+
' "desc": "this is repo_b",',
|
280
|
+
' "language": "Ruby"',
|
281
|
+
'}',
|
282
|
+
].join("\n")
|
283
|
+
|
284
|
+
# create repo_3
|
285
|
+
FileUtils.mkdir_p "/path/to/repo_3"
|
286
|
+
FileUtils.mkdir_p "/path/to/repo_3/.git"
|
287
|
+
FileUtils.touch "/path/to/repo_3/snippet.json"
|
288
|
+
File.write "/path/to/repo_3/snippet.json", [
|
289
|
+
'{',
|
290
|
+
' "name": "repo_3",',
|
291
|
+
' "desc": "this is repo_3",',
|
292
|
+
' "language": "Ruby"',
|
293
|
+
'}',
|
294
|
+
].join("\n")
|
295
|
+
end # before
|
296
|
+
|
297
|
+
context "create three instances" do
|
298
|
+
|
299
|
+
let(:instance_1) { BaseRepository.new("/path/to/repo_1") }
|
300
|
+
let(:instance_b) { BaseRepository.new("/path/to/repo_b") }
|
301
|
+
let(:instance_3) { BaseRepository.new("/path/to/repo_3") }
|
302
|
+
|
303
|
+
before do
|
304
|
+
instance_1.load_snippet_json
|
305
|
+
instance_b.load_snippet_json
|
306
|
+
instance_3.load_snippet_json
|
307
|
+
end
|
308
|
+
|
309
|
+
context "name" do
|
310
|
+
it { expect(instance_1.name).to eq "repo_1" }
|
311
|
+
it { expect(instance_b.name).to eq "repo_b" }
|
312
|
+
it { expect(instance_3.name).to eq "repo_3" }
|
313
|
+
end
|
314
|
+
|
315
|
+
context "create cache" do
|
316
|
+
|
317
|
+
# create cache dir
|
318
|
+
let(:cache_path) { "/path/to/cache" }
|
319
|
+
before { FileUtils.mkdir_p(cache_path) }
|
320
|
+
|
321
|
+
before do
|
322
|
+
expect(instance_1).to receive(:commit_id).and_return commit_id
|
323
|
+
expect(instance_b).to receive(:commit_id).and_return commit_id
|
324
|
+
expect(instance_3).to receive(:commit_id).and_return commit_id
|
325
|
+
end
|
326
|
+
|
327
|
+
before do
|
328
|
+
instance_1.create_cache(cache_path)
|
329
|
+
instance_b.create_cache(cache_path)
|
330
|
+
instance_3.create_cache(cache_path)
|
331
|
+
end
|
332
|
+
|
333
|
+
context "snippet.json" do
|
334
|
+
|
335
|
+
context "repo_1" do
|
336
|
+
let(:result) do
|
337
|
+
JSON.parse File.read "#{cache_path}/repo_1/#{commit_id[0..7]}/snippet.json"
|
338
|
+
end
|
339
|
+
it { expect(result["name"]).to eq "repo_1" }
|
340
|
+
it { expect(result["desc"]).to eq "this is repo_1" }
|
341
|
+
it { expect(result["language"]).to eq "Ruby" }
|
342
|
+
end
|
343
|
+
|
344
|
+
context "repo_b" do
|
345
|
+
let(:result) do
|
346
|
+
JSON.parse File.read "#{cache_path}/repo_b/#{commit_id[0..7]}/snippet.json"
|
347
|
+
end
|
348
|
+
it { expect(result["name"]).to eq "repo_b" }
|
349
|
+
it { expect(result["desc"]).to eq "this is repo_b" }
|
350
|
+
it { expect(result["language"]).to eq "Ruby" }
|
351
|
+
end
|
352
|
+
|
353
|
+
context "repo_3" do
|
354
|
+
let(:result) do
|
355
|
+
JSON.parse File.read "#{cache_path}/repo_3/#{commit_id[0..7]}/snippet.json"
|
356
|
+
end
|
357
|
+
it { expect(result["name"]).to eq "repo_3" }
|
358
|
+
it { expect(result["desc"]).to eq "this is repo_3" }
|
359
|
+
it { expect(result["language"]).to eq "Ruby" }
|
360
|
+
end
|
361
|
+
|
362
|
+
end # snippet.json
|
363
|
+
|
364
|
+
end # create cache
|
365
|
+
|
366
|
+
end # create three instances
|
367
|
+
|
368
|
+
end # there are three repos
|
369
|
+
|
370
|
+
end # .new
|
371
|
+
|
372
|
+
end # BaseRepository
|
373
|
+
|
374
|
+
end # SocialSnippet::Repository
|
375
|
+
|