gistribute 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/VERSION +1 -1
- data/lib/cli/install.rb +1 -0
- data/lib/cli/upload.rb +1 -1
- data/lib/cli.rb +1 -0
- data/spec/gistribute/cli_install_spec.rb +50 -22
- data/spec/gistribute/cli_upload_spec.rb +39 -0
- data/spec/gistribute_spec.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97e259b2b9206eb05470a31911d121166d9ed55d94ea1eb2b2be860c9befec47
|
4
|
+
data.tar.gz: 97e818cbd5638d50782e2a95a910da6ab6c83724a6dcefbe01bd4699c4757f68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f45614e316c434a25cb92bca518faee4e3101ae8beadbc7ce60fbd4b73ac90ff5b5350fec966c078af5c79eb04dae91ee7609c754b443f2fa37b2bb0e4ad18d
|
7
|
+
data.tar.gz: f3977be4e4fbd3dbb29fb0b5569afdbea87f3bf9b8bf9e8569fd4dc155bed0410265688499f35fdc355c6a9c88a07a7c28de07f0b05682865e2e71f1e9a7f6c7
|
data/README.md
CHANGED
@@ -32,6 +32,13 @@ use the name of the file (without the path to it) as the default description.
|
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
35
|
+
For a detailed description of the available options, try one of the following:
|
36
|
+
|
37
|
+
```sh
|
38
|
+
gistribute upload -h
|
39
|
+
gistribute install -h
|
40
|
+
```
|
41
|
+
|
35
42
|
### Uploads
|
36
43
|
|
37
44
|
To upload a gistribution, use the `upload` subcommand and pass in as many files
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3
|
1
|
+
0.3.1
|
data/lib/cli/install.rb
CHANGED
@@ -26,6 +26,7 @@ module Gistribute
|
|
26
26
|
# check to see if it's empty- if not, put newlines on each side so that it
|
27
27
|
# will be padded when displayed in the output.
|
28
28
|
gist_description = gist.description.gsub(/(.{1,79})(\s+|\Z)/, "\\1\n").strip
|
29
|
+
.sub(/^\[gistribut(e|ion)\] ?/, "")
|
29
30
|
gist_description = "\n#{gist_description}\n" unless gist_description.empty?
|
30
31
|
|
31
32
|
# Process files
|
data/lib/cli/upload.rb
CHANGED
data/lib/cli.rb
CHANGED
@@ -8,14 +8,19 @@ MULTI_FILENAMES = ["file1", "dir/file2"].freeze
|
|
8
8
|
SINGLE_FILE_CONTENTS = "Line 1\nLine 2\n"
|
9
9
|
|
10
10
|
# Test Gists
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
|
12
|
+
GIST_IDS = {
|
13
|
+
pub_single_file: "4346763",
|
14
|
+
sec_single_file: "5fa3c6bab88036e95d62cadf15128ec3",
|
15
|
+
no_title: "5865a130f9cf40acd9f0e85d15e601a7",
|
16
|
+
no_pipe_spacing: "5677679b0db25054521753e5d59bed3d",
|
17
|
+
non_existent_dir: "8c86bf9cda921ebe7ad1bf0c46afb108",
|
18
|
+
multi_file: "8d4a2a4c8fe0b1427fed39c939857a40",
|
19
|
+
cwd: "3c7006e629fcc54262ef02a5b2204735",
|
20
|
+
home: "acb6caa80886101a68c5c85e4c100ddb",
|
21
|
+
gist_description: "332d3f90378380a00614a088d9c179c5",
|
22
|
+
no_gist_description: "b35c3fcf05af11b7efc1a5dbd11d23be"
|
23
|
+
}
|
19
24
|
|
20
25
|
def test_single_file(id, path)
|
21
26
|
before { run "install", id }
|
@@ -46,10 +51,10 @@ describe Gistribute::CLI do
|
|
46
51
|
before { simulate_user_input "y\n" }
|
47
52
|
|
48
53
|
{
|
49
|
-
"public single file":
|
50
|
-
"secret single file":
|
51
|
-
"no title":
|
52
|
-
"no || spacing":
|
54
|
+
"public single file": GIST_IDS[:pub_single_file],
|
55
|
+
"secret single file": GIST_IDS[:sec_single_file],
|
56
|
+
"no title": GIST_IDS[:no_title],
|
57
|
+
"no || spacing": GIST_IDS[:no_pipe_spacing]
|
53
58
|
}.each do |description, id|
|
54
59
|
context "when run with a #{description} Gist" do
|
55
60
|
test_single_file id, TEMP
|
@@ -57,7 +62,7 @@ describe Gistribute::CLI do
|
|
57
62
|
end
|
58
63
|
|
59
64
|
context "when given a directory that doesn't exist" do
|
60
|
-
before { run "install",
|
65
|
+
before { run "install", GIST_IDS[:non_existent_dir] }
|
61
66
|
|
62
67
|
let(:file_contents) { File.read "#{TEMP}/#{NEW_DIR_FILENAME}" }
|
63
68
|
|
@@ -67,7 +72,7 @@ describe Gistribute::CLI do
|
|
67
72
|
end
|
68
73
|
|
69
74
|
context "when run with a multi-file Gist" do
|
70
|
-
before { run "install",
|
75
|
+
before { run "install", GIST_IDS[:multi_file] }
|
71
76
|
|
72
77
|
let(:file1_contents) { File.read "#{TEMP}/#{MULTI_FILENAMES[0]}" }
|
73
78
|
let(:file2_contents) { File.read "#{TEMP}/#{MULTI_FILENAMES[1]}" }
|
@@ -81,11 +86,11 @@ describe Gistribute::CLI do
|
|
81
86
|
end
|
82
87
|
|
83
88
|
context "when given a file for the current working directory" do
|
84
|
-
test_single_file
|
89
|
+
test_single_file GIST_IDS[:cwd], Dir.pwd
|
85
90
|
end
|
86
91
|
|
87
92
|
context "when given a file for the home directory" do
|
88
|
-
test_single_file
|
93
|
+
test_single_file GIST_IDS[:home], Dir.home
|
89
94
|
end
|
90
95
|
|
91
96
|
context "when given a bad ID (404)" do
|
@@ -105,12 +110,35 @@ describe Gistribute::CLI do
|
|
105
110
|
expect($stderr).to have_received(:puts).with("bad")
|
106
111
|
end
|
107
112
|
end
|
113
|
+
|
114
|
+
context "when given a Gist with only a description" do
|
115
|
+
before { run "install", GIST_IDS[:gist_description] }
|
116
|
+
|
117
|
+
it "prints the description" do
|
118
|
+
expect($stdout).to have_received(:write)
|
119
|
+
.with(a_string_including("test description"))
|
120
|
+
end
|
121
|
+
|
122
|
+
it "removes the `[gistribution]` from the beginning" do
|
123
|
+
expect($stdout).not_to have_received(:write)
|
124
|
+
.with(a_string_including("[gistribution]"))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when given a Gist with only `[gistribution]` in the description" do
|
129
|
+
before { run "install", GIST_IDS[:no_gist_description] }
|
130
|
+
|
131
|
+
it "doesn't print the description" do
|
132
|
+
expect($stdout).not_to have_received(:write)
|
133
|
+
.with(a_string_including("[gistribution]"))
|
134
|
+
end
|
135
|
+
end
|
108
136
|
end
|
109
137
|
|
110
138
|
context "when user inputs nothing at the installation prompt" do
|
111
139
|
before do
|
112
140
|
simulate_user_input "\n"
|
113
|
-
run "install",
|
141
|
+
run "install", GIST_IDS[:pub_single_file]
|
114
142
|
end
|
115
143
|
|
116
144
|
it "saves the file" do
|
@@ -122,7 +150,7 @@ describe Gistribute::CLI do
|
|
122
150
|
context "when user inputs `#{ch}` at the installation prompt" do
|
123
151
|
before do
|
124
152
|
simulate_user_input "#{ch}\n"
|
125
|
-
run "install",
|
153
|
+
run "install", GIST_IDS[:pub_single_file]
|
126
154
|
end
|
127
155
|
|
128
156
|
it "doesn't save the file" do
|
@@ -147,7 +175,7 @@ describe Gistribute::CLI do
|
|
147
175
|
context "when the user inputs `y` at the file overwrite prompts" do
|
148
176
|
before do
|
149
177
|
simulate_user_input "y\n", "y\n", "y\n"
|
150
|
-
run "install",
|
178
|
+
run "install", GIST_IDS[:multi_file]
|
151
179
|
end
|
152
180
|
|
153
181
|
it "downloads the files into the correct locations" do
|
@@ -158,7 +186,7 @@ describe Gistribute::CLI do
|
|
158
186
|
context "when the user inputs `n` at the file overwrite prompts" do
|
159
187
|
before do
|
160
188
|
simulate_user_input "y\n", "n\n", "n\n"
|
161
|
-
run "install",
|
189
|
+
run "install", GIST_IDS[:multi_file]
|
162
190
|
end
|
163
191
|
|
164
192
|
it "doesn't download the files" do
|
@@ -169,7 +197,7 @@ describe Gistribute::CLI do
|
|
169
197
|
context "with the `--force` flag" do
|
170
198
|
before do
|
171
199
|
simulate_user_input "y\n"
|
172
|
-
run "install", "--force",
|
200
|
+
run "install", "--force", GIST_IDS[:multi_file]
|
173
201
|
end
|
174
202
|
|
175
203
|
it "overwrites the files without prompting" do
|
@@ -181,7 +209,7 @@ describe Gistribute::CLI do
|
|
181
209
|
end
|
182
210
|
|
183
211
|
context "when ran with the --yes flag" do
|
184
|
-
before { run "install", "--yes",
|
212
|
+
before { run "install", "--yes", GIST_IDS[:pub_single_file] }
|
185
213
|
|
186
214
|
let(:file_contents) { File.read "#{TEMP}/#{FILENAME}" }
|
187
215
|
|
@@ -157,5 +157,44 @@ describe Gistribute::CLI do
|
|
157
157
|
expect(octokit_client).to have_received(:create_gist)
|
158
158
|
end
|
159
159
|
end
|
160
|
+
|
161
|
+
context "with the `--relative` flag" do
|
162
|
+
context "with a single file" do
|
163
|
+
before do
|
164
|
+
File.write(FILENAME, SINGLE_FILE_CONTENT)
|
165
|
+
simulate_user_input "Test File\n", "y\n"
|
166
|
+
run "upload", "--relative", FILENAME
|
167
|
+
end
|
168
|
+
|
169
|
+
after { File.delete FILENAME }
|
170
|
+
|
171
|
+
it "uploads with a relative file path" do
|
172
|
+
expect(octokit_client).to have_received(:create_gist)
|
173
|
+
.with(a_hash_including(files: { "Test File || #{FILENAME}" => anything }))
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "with a single directory" do
|
178
|
+
let(:test_dir) { "test_dir" }
|
179
|
+
|
180
|
+
before do
|
181
|
+
FileUtils.mkdir test_dir
|
182
|
+
[1, 2].each { |n| FileUtils.touch "#{test_dir}/file#{n}" }
|
183
|
+
|
184
|
+
simulate_user_input "File 1\n", "File 2\n", "y\n"
|
185
|
+
run "upload", "--relative", test_dir
|
186
|
+
end
|
187
|
+
|
188
|
+
after { FileUtils.rm_rf test_dir }
|
189
|
+
|
190
|
+
it "uploads with a relative file path" do
|
191
|
+
expect(octokit_client).to have_received(:create_gist)
|
192
|
+
.with(a_hash_including(files: {
|
193
|
+
"File 1 || #{test_dir}|file1" => anything,
|
194
|
+
"File 2 || #{test_dir}|file2" => anything
|
195
|
+
}))
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
160
199
|
end
|
161
200
|
end
|
data/spec/gistribute_spec.rb
CHANGED
@@ -4,7 +4,9 @@ require "spec_helper"
|
|
4
4
|
|
5
5
|
describe Gistribute do
|
6
6
|
describe "::parse_id" do
|
7
|
-
[
|
7
|
+
%i[pub_single_file sec_single_file].each do |gist|
|
8
|
+
id = GIST_IDS[gist]
|
9
|
+
|
8
10
|
[
|
9
11
|
"https://gist.github.com/username/#{id}",
|
10
12
|
"https://gist.github.com/#{id}",
|