hrk 0.0.8 → 1.0.0
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 +4 -4
- data/README.md +73 -10
- data/lib/hrk.rb +2 -2
- data/lib/hrk/env.rb +59 -11
- data/lib/hrk/execute.rb +2 -3
- data/lib/hrk/execute/help.rb +2 -2
- data/lib/hrk/heroku.rb +2 -2
- data/lib/hrk/version.rb +3 -0
- data/spec/hrk/env_spec.rb +283 -0
- data/spec/hrk/execute/command_spec.rb +11 -11
- data/spec/hrk/execute_spec.rb +9 -0
- data/spec/hrk/heroku_spec.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dfbf2f64a50461372620e5d7aa9bcc4295de6d5
|
4
|
+
data.tar.gz: ab1f2fe43247946ce291faadadaeb4e10f7fcb2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cbe4f176099d1f231cc492ec591e6307255ee5e46bb051cd984854576065305dac3c17dcf959199725522978703eb6a1c69a2f82a95fa99e5216be9e650e28a
|
7
|
+
data.tar.gz: 905d3bb4978f67bdbfd55a3e67897e7559a88254a59d8f1bc45d33fa9759f272603de513972195a8f54f46ef364b1ddad7cf416140cf6db1129a282e3038af94
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Hrk
|
2
|
+
[](http://badge.fury.io/rb/hrk)
|
3
|
+
[](https://travis-ci.org/Bastes/hrk)
|
4
|
+
[](https://gemnasium.com/Bastes/hrk)
|
2
5
|
|
3
|
-
Hrk
|
6
|
+
Hrk remembers your heroku remotes for you.
|
4
7
|
|
5
8
|
```
|
6
9
|
,|
|
@@ -21,17 +24,19 @@ Hrk 2 swim like a dolphin in a sea of heroku commands
|
|
21
24
|
``--'' `
|
22
25
|
```
|
23
26
|
|
27
|
+
Hrk 2 swim like a dolphin in a sea of heroku commands
|
28
|
+
|
24
29
|
## Getting started
|
25
30
|
|
26
31
|
You can install the Hrk gem using the gem command:
|
27
32
|
|
28
|
-
```
|
33
|
+
```bash
|
29
34
|
$ gem install hrk
|
30
35
|
```
|
31
36
|
|
32
37
|
Or through bundler:
|
33
38
|
|
34
|
-
```
|
39
|
+
```ruby
|
35
40
|
# in your Gemfile
|
36
41
|
gem 'hrk', group: :development
|
37
42
|
|
@@ -39,7 +44,7 @@ $ bundle install
|
|
39
44
|
```
|
40
45
|
|
41
46
|
And enjoy the hrk command awesome power:
|
42
|
-
```
|
47
|
+
```bash
|
43
48
|
$ hrk logs -r your-heroku-remote-name && hrk run console
|
44
49
|
```
|
45
50
|
|
@@ -50,7 +55,7 @@ It's a command that calls the heroku toolbelt command for you, remembers the
|
|
50
55
|
name of the previous remote so you don't have to re-type it again and again
|
51
56
|
and again each time you want to chain heroku commands.
|
52
57
|
|
53
|
-
For example, let's say I've got an heroku app
|
58
|
+
For example, let's say I've got an heroku app which remote is called:
|
54
59
|
|
55
60
|
> this-really-long-remote-name
|
56
61
|
|
@@ -75,13 +80,18 @@ And sometimes you mistype, and the chain breaks in the middle, and it sucks.
|
|
75
80
|
**Wait, I can do something like that**
|
76
81
|
|
77
82
|
```bash
|
78
|
-
$ export
|
79
|
-
heroku run rake do:something:else
|
80
|
-
heroku run rake other:thing
|
81
|
-
heroku run rake yet:another:task
|
83
|
+
$ export HEROKU_APP=this-app-name-that-is-usually-even-longer-than-the-remote-name && \
|
84
|
+
heroku run rake do:something:else && \
|
85
|
+
heroku run rake other:thing && \
|
86
|
+
heroku run rake yet:another:task
|
82
87
|
```
|
83
88
|
|
84
|
-
Yup
|
89
|
+
Yup, it works.
|
90
|
+
Still feels like one command too many.
|
91
|
+
Still have to remember the names of my apps for each project instead of using my
|
92
|
+
aptly, conventionnaly named remotes ('test', 'staging', 'prod'...).
|
93
|
+
|
94
|
+
Isn't there a better way?
|
85
95
|
|
86
96
|
**Hrk to the rescue!**
|
87
97
|
|
@@ -157,10 +167,63 @@ $ hrk maintenance:on -a my-super-duper-app && \ # happens on my-super-duper-app
|
|
157
167
|
hrk maintenance:off # aaand on my-super-duper-app
|
158
168
|
```
|
159
169
|
|
170
|
+
**...if I don't chain commands?**
|
171
|
+
|
172
|
+
Hrk has been designed to help when chaining commands, but it will remember your
|
173
|
+
last remote until you close your terminal. So this will work:
|
174
|
+
|
175
|
+
```bash
|
176
|
+
$ hrk logs -r demo
|
177
|
+
...
|
178
|
+
$ hrk console # happens on demo
|
179
|
+
```
|
180
|
+
|
181
|
+
This also means you have to be a little careful not to forget on which remote
|
182
|
+
you are. We are currently planning on adding a little more security there, so
|
183
|
+
stay tuned.
|
184
|
+
|
185
|
+
## Where will it run?
|
186
|
+
|
187
|
+
It should run on Linux and MacOSX, provided you've installed ruby.
|
188
|
+
|
189
|
+
It might run on Windows, although it hasn't been tested and relies on system
|
190
|
+
commands that might be different. If you're a windows user and would like to
|
191
|
+
give it a try, please do send us your issues and / or pull requests to make hrk
|
192
|
+
run there.
|
193
|
+
|
160
194
|
## Do I still need the heroku toolbelt?
|
161
195
|
|
162
196
|
Yes. The hrk command calls the heroku command for you, it does not replace it.
|
163
197
|
|
198
|
+
## How do I contribute?
|
199
|
+
|
200
|
+
In many ways:
|
201
|
+
|
202
|
+
**If you're having fun using hrk...**
|
203
|
+
|
204
|
+
...you can of course give your feedback and ideas for improvements through
|
205
|
+
[github issues](https://github.com/Bastes/hrk/issues).
|
206
|
+
|
207
|
+
**If you'd like to tweak something...**
|
208
|
+
|
209
|
+
Fork the project on the [github page](https://github.com/Bastes/hrk/issues)
|
210
|
+
and do what you want with it, that's what free software (and github) is for.
|
211
|
+
|
212
|
+
If you added something awesome or killed a nasty bug and want everybody to
|
213
|
+
rejoice, you can send a pull request and it'll be merged (or you'll receive an
|
214
|
+
explaination why it won't as is).
|
215
|
+
|
216
|
+
Pull requests with specs improve their chances to be accepted, so don't shy away
|
217
|
+
from adding / changing / fixing the specs.
|
218
|
+
|
219
|
+
If you'd like to to help on current issues, feel also free to browse them and
|
220
|
+
attack the ones you'd like to get your hands on. Pull requests that fix issues
|
221
|
+
are always welcome.
|
222
|
+
|
223
|
+
And if you read the code and feel your eyes start to bleed, maybe you can
|
224
|
+
notify me (preferably after consulting a good eye doctor). Code reviews lead to
|
225
|
+
better code, and better code makes hrk happy.
|
226
|
+
|
164
227
|
## Very important warning!
|
165
228
|
|
166
229
|
Hrk is pronounced like "a shark" because it's funny.
|
data/lib/hrk.rb
CHANGED
data/lib/hrk/env.rb
CHANGED
@@ -5,30 +5,78 @@ require 'tmpdir'
|
|
5
5
|
|
6
6
|
module Hrk
|
7
7
|
class Env
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
attr_reader :tty_digest
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@tty_digest = Digest::MD5.hexdigest(`tty`)
|
12
|
+
end
|
13
|
+
|
14
|
+
def schedule_cleanup!
|
15
|
+
unless cleanup_scheduled?
|
16
|
+
self.pid = fork do
|
17
|
+
at_exit { cleanup! }
|
18
|
+
while(true) do
|
19
|
+
`tty`
|
20
|
+
exit if $? != 0
|
21
|
+
sleep 1
|
22
|
+
end
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
|
27
|
+
def cleanup!
|
28
|
+
remote_path.delete if remote_path.exist?
|
29
|
+
pid_path.delete if pid_path.exist?
|
30
|
+
end
|
31
|
+
|
32
|
+
def remote= args
|
33
|
+
schedule_cleanup!
|
34
|
+
remote_path.write args.join(' ') unless remote == args
|
35
|
+
end
|
36
|
+
|
16
37
|
def remote
|
17
|
-
|
38
|
+
remote_path.read.split(' ', 2) if remote?
|
18
39
|
end
|
19
40
|
|
20
41
|
def remote?
|
21
|
-
|
42
|
+
remote_path.exist?
|
22
43
|
end
|
23
44
|
|
24
45
|
def tmp_path
|
25
|
-
|
26
|
-
new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, 'hrk')).
|
46
|
+
tmp_dir.join('hrk').
|
27
47
|
tap { |path| FileUtils.mkdir_p(path) unless path.exist? }
|
28
48
|
end
|
29
49
|
|
30
|
-
def
|
31
|
-
|
50
|
+
def tmp_dir
|
51
|
+
Pathname.new(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir)
|
52
|
+
end
|
53
|
+
|
54
|
+
def remote_path
|
55
|
+
tmp_path.join tty_digest
|
56
|
+
end
|
57
|
+
|
58
|
+
def cleanup_scheduled?
|
59
|
+
begin
|
60
|
+
pid? && Process.kill(0, pid)
|
61
|
+
rescue Errno::ESRCH
|
62
|
+
false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def pid
|
67
|
+
pid_path.read.to_i if pid?
|
68
|
+
end
|
69
|
+
|
70
|
+
def pid?
|
71
|
+
pid_path.exist?
|
72
|
+
end
|
73
|
+
|
74
|
+
def pid= value
|
75
|
+
pid_path.write(value)
|
76
|
+
end
|
77
|
+
|
78
|
+
def pid_path
|
79
|
+
tmp_path.join "#{tty_digest}.pid"
|
32
80
|
end
|
33
81
|
end
|
34
82
|
end
|
data/lib/hrk/execute.rb
CHANGED
data/lib/hrk/execute/help.rb
CHANGED
@@ -9,7 +9,7 @@ module Hrk
|
|
9
9
|
if args.empty? || args.first =~ %r(\A(?:(?:(?:-)?h)|(?:(?:--)?help))\Z)
|
10
10
|
display || true
|
11
11
|
else
|
12
|
-
fallback
|
12
|
+
fallback(*args)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -40,7 +40,7 @@ https://github.com/Bastes/hrk
|
|
40
40
|
|
41
41
|
def fallback *args
|
42
42
|
if @fallback
|
43
|
-
@fallback.call
|
43
|
+
@fallback.call(*args)
|
44
44
|
else
|
45
45
|
raise ArgumentError.new
|
46
46
|
end
|
data/lib/hrk/heroku.rb
CHANGED
@@ -5,13 +5,13 @@ module Hrk
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def call *command
|
8
|
-
validate!
|
8
|
+
validate! command
|
9
9
|
system 'heroku', *(command + @remote)
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
def validate!
|
14
|
+
def validate! command
|
15
15
|
remote = (command.each_cons(2).detect { |(parameter, _)| parameter =~ %r{\A-[ar]\Z} }.join ' ' rescue nil)
|
16
16
|
raise ExplicitApplicationError.new, "You're calling a command on remote #{@remote.join " "} yet the command explicitly references #{remote}" if remote
|
17
17
|
end
|
data/lib/hrk/version.rb
ADDED
@@ -0,0 +1,283 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Hrk::Env do
|
4
|
+
subject(:env) { Hrk::Env.new }
|
5
|
+
|
6
|
+
shared_context 'fake remote_path' do
|
7
|
+
let(:remote_path) { double(Pathname) }
|
8
|
+
|
9
|
+
before { allow(remote_path).to receive(:delete) }
|
10
|
+
before { allow(remote_path).to receive(:write) }
|
11
|
+
before { allow(env).to receive(:remote_path).and_return remote_path }
|
12
|
+
end
|
13
|
+
|
14
|
+
shared_context 'fake pid_path' do
|
15
|
+
let(:pid_path) { double(Pathname) }
|
16
|
+
|
17
|
+
before { allow(pid_path).to receive(:write) }
|
18
|
+
before { allow(pid_path).to receive(:delete) }
|
19
|
+
before { allow(env).to receive(:pid_path).and_return pid_path }
|
20
|
+
end
|
21
|
+
|
22
|
+
shared_context 'fake tty' do
|
23
|
+
let(:tty) { "/dev/pts/#{rand(1..9)}" }
|
24
|
+
|
25
|
+
before { allow_any_instance_of(Hrk::Env).to receive(:`).and_return(tty) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#initialize' do
|
29
|
+
include_context 'fake tty'
|
30
|
+
|
31
|
+
subject!(:env) { Hrk::Env.new }
|
32
|
+
|
33
|
+
it { expect(env.tty_digest).to eq Digest::MD5.hexdigest(tty) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#cleanup!' do
|
37
|
+
include_context 'fake remote_path'
|
38
|
+
include_context 'fake pid_path'
|
39
|
+
|
40
|
+
let(:the_remote_pre_exist) { [true, false].sample }
|
41
|
+
let(:the_pid_pre_exist) { [true, false].sample }
|
42
|
+
before { allow(remote_path).to receive(:exist?).and_return the_remote_pre_exist }
|
43
|
+
before { allow(pid_path).to receive(:exist?).and_return the_pid_pre_exist }
|
44
|
+
|
45
|
+
before { env.cleanup! }
|
46
|
+
|
47
|
+
context 'the remote file pre-exists' do
|
48
|
+
let(:the_remote_pre_exist) { true }
|
49
|
+
|
50
|
+
it { expect(remote_path).to have_received(:delete) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'the remote file does not pre-exists' do
|
54
|
+
let(:the_remote_pre_exist) { false }
|
55
|
+
|
56
|
+
it { expect(remote_path).not_to have_received(:delete) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'the pid file pre-exists' do
|
60
|
+
let(:the_pid_pre_exist) { true }
|
61
|
+
|
62
|
+
it { expect(pid_path).to have_received(:delete) }
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'the pid file does not pre-exists' do
|
66
|
+
let(:the_pid_pre_exist) { false }
|
67
|
+
|
68
|
+
it { expect(pid_path).not_to have_received(:delete) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#remote=' do
|
73
|
+
include_context 'fake remote_path'
|
74
|
+
|
75
|
+
let(:remote_arg) { "-#{%w(a r).sample}" }
|
76
|
+
let(:remote_name) { "remote##{rand(1..9)}" }
|
77
|
+
|
78
|
+
before { allow(env).to receive(:remote).and_return(previous_remote) }
|
79
|
+
before { allow(env).to receive(:schedule_cleanup!) }
|
80
|
+
|
81
|
+
before { env.remote = [remote_arg, remote_name] }
|
82
|
+
|
83
|
+
context 'no previous remote' do
|
84
|
+
let(:previous_remote) { nil }
|
85
|
+
|
86
|
+
it { expect(remote_path).to have_received(:write).with("#{remote_arg} #{remote_name}") }
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'the previous remote is different' do
|
90
|
+
let(:previous_remote) { ['-r', 'previous'] }
|
91
|
+
|
92
|
+
it { expect(remote_path).to have_received(:write).with("#{remote_arg} #{remote_name}") }
|
93
|
+
it { expect(env).to have_received(:schedule_cleanup!) }
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'the previous remote is identical' do
|
97
|
+
let(:previous_remote) { [remote_arg, remote_name] }
|
98
|
+
|
99
|
+
it { expect(remote_path).not_to have_received(:write) }
|
100
|
+
it { expect(env).to have_received(:schedule_cleanup!) }
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#remote' do
|
105
|
+
include_context 'fake remote_path'
|
106
|
+
|
107
|
+
before { allow(remote_path).to receive(:exist?).and_return it_pre_exist }
|
108
|
+
before { allow(remote_path).to receive(:read).and_return remote }
|
109
|
+
|
110
|
+
context 'no remote file exists' do
|
111
|
+
let(:it_pre_exist) { false }
|
112
|
+
let(:remote) { nil }
|
113
|
+
|
114
|
+
it { expect(env.remote).to eq nil }
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'the remote file exists' do
|
118
|
+
let(:it_pre_exist) { true }
|
119
|
+
let(:remote_arg) { "-#{%w(a r).sample}" }
|
120
|
+
let(:remote_name) { "remote##{rand(1..9)}" }
|
121
|
+
let(:remote) { "#{remote_arg} #{remote_name}" }
|
122
|
+
|
123
|
+
it { expect(env.remote).to eq [remote_arg, remote_name] }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#remote?' do
|
128
|
+
include_context 'fake remote_path'
|
129
|
+
|
130
|
+
before { allow(remote_path).to receive(:exist?).and_return it_pre_exist }
|
131
|
+
|
132
|
+
context 'the remote file exists' do
|
133
|
+
let(:it_pre_exist) { true }
|
134
|
+
|
135
|
+
it { expect(env.remote?).to eq true }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'the remote file does not exist' do
|
139
|
+
let(:it_pre_exist) { false }
|
140
|
+
|
141
|
+
it { expect(env.remote?).to eq false }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#tmp_path' do
|
146
|
+
let(:some_dir) { Pathname.new "/some#{rand(1..9)}/fake/dir" }
|
147
|
+
before { allow(env).to receive(:tmp_dir).and_return(some_dir) }
|
148
|
+
before { allow_any_instance_of(Pathname).to receive(:exist?).and_return(it_pre_exist) }
|
149
|
+
before { allow(FileUtils).to receive(:mkdir_p) }
|
150
|
+
|
151
|
+
subject!(:path) { env.tmp_path }
|
152
|
+
|
153
|
+
context 'the path did not already exist' do
|
154
|
+
let(:it_pre_exist) { false }
|
155
|
+
|
156
|
+
it { expect(path).to eq Pathname.new("#{some_dir}/hrk") }
|
157
|
+
it { expect(FileUtils).to have_received(:mkdir_p).with(path) }
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'the path did already exist' do
|
161
|
+
let(:it_pre_exist) { true }
|
162
|
+
|
163
|
+
it { expect(path).to eq Pathname.new("#{some_dir}/hrk") }
|
164
|
+
it { expect(FileUtils).not_to have_received(:mkdir_p) }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#tmp_dir' do
|
169
|
+
let(:tmpdir) { "/another/silly/path#{rand(1..9)}" }
|
170
|
+
before { allow(Dir).to receive(:tmpdir).and_return(tmpdir) }
|
171
|
+
before { allow(ENV).to receive(:[]).with('XDG_RUNTIME_DIR').and_return(xdg_runtime_dir) }
|
172
|
+
context 'there is an XDG_RUNTIME_DIR in the ENV' do
|
173
|
+
let(:xdg_runtime_dir) { "/yet_again/a#{rand(1..9)}/folder" }
|
174
|
+
|
175
|
+
it { expect(env.tmp_dir).to eq Pathname.new(xdg_runtime_dir) }
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'there is no XDG_RUNTIME_DIR in the ENV' do
|
179
|
+
let(:xdg_runtime_dir) { nil }
|
180
|
+
|
181
|
+
it { expect(env.tmp_dir).to eq Pathname.new(tmpdir) }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#remote_path' do
|
186
|
+
include_context 'fake tty'
|
187
|
+
|
188
|
+
let(:some_dir) { Pathname.new "/and#{rand(1..9)}/another_/dir" }
|
189
|
+
|
190
|
+
before { allow(env).to receive(:tmp_path).and_return(Pathname.new(some_dir)) }
|
191
|
+
|
192
|
+
it { expect(env.remote_path).to eq Pathname.new("#{some_dir}/#{Digest::MD5.hexdigest(tty)}") }
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '#cleanup_scheduled?' do
|
196
|
+
let(:pid) { rand(1000..99999) }
|
197
|
+
before { allow(env).to receive(:pid).and_return(pid) }
|
198
|
+
before { allow(env).to receive(:pid?).and_return(the_pid_exist) }
|
199
|
+
|
200
|
+
context 'there is no pid file' do
|
201
|
+
let(:the_pid_exist) { false }
|
202
|
+
let(:the_process_be_alive) { [false, true].sample }
|
203
|
+
|
204
|
+
it { expect(env.cleanup_scheduled?).to be_falsy }
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'there is a pid file' do
|
208
|
+
let(:the_pid_exist) { true }
|
209
|
+
|
210
|
+
context 'the process is alived' do
|
211
|
+
let(:the_process_be_alive) { true }
|
212
|
+
before { allow(Process).to receive(:kill).with(0, pid).and_return(the_process_be_alive) }
|
213
|
+
|
214
|
+
it { expect(env.cleanup_scheduled?).to be_truthy }
|
215
|
+
end
|
216
|
+
|
217
|
+
context 'the process is dead' do
|
218
|
+
let(:the_process_be_alive) { false }
|
219
|
+
before { allow(Process).to receive(:kill).with(0, pid).and_raise(Errno::ESRCH) }
|
220
|
+
|
221
|
+
it { expect(env.cleanup_scheduled?).to be_falsy }
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '#pid' do
|
227
|
+
include_context 'fake pid_path'
|
228
|
+
|
229
|
+
before { allow(pid_path).to receive(:exist?).and_return it_pre_exist }
|
230
|
+
before { allow(pid_path).to receive(:read).and_return pid }
|
231
|
+
|
232
|
+
context 'no pid file exists' do
|
233
|
+
let(:it_pre_exist) { false }
|
234
|
+
let(:pid) { nil }
|
235
|
+
|
236
|
+
it { expect(env.pid).to eq nil }
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'the pid file exists' do
|
240
|
+
let(:it_pre_exist) { true }
|
241
|
+
let(:pid) { "#{rand(1000..99999)}" }
|
242
|
+
|
243
|
+
it { expect(env.pid).to eq pid.to_i }
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '#pid?' do
|
248
|
+
include_context 'fake pid_path'
|
249
|
+
|
250
|
+
before { allow(pid_path).to receive(:exist?).and_return it_pre_exist }
|
251
|
+
|
252
|
+
context 'the pid file exists' do
|
253
|
+
let(:it_pre_exist) { true }
|
254
|
+
|
255
|
+
it { expect(env.pid?).to eq true }
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'the pid file does not exist' do
|
259
|
+
let(:it_pre_exist) { false }
|
260
|
+
|
261
|
+
it { expect(env.pid?).to eq false }
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe '#pid=' do
|
266
|
+
let(:pid) { rand(1000..99999) }
|
267
|
+
include_context 'fake pid_path'
|
268
|
+
|
269
|
+
before { env.pid = pid }
|
270
|
+
|
271
|
+
it { expect(pid_path).to have_received(:write).with(pid) }
|
272
|
+
end
|
273
|
+
|
274
|
+
describe '#pid_path' do
|
275
|
+
include_context 'fake tty'
|
276
|
+
|
277
|
+
let(:some_dir) { Pathname.new "/and#{rand(1..9)}/another_/dir" }
|
278
|
+
|
279
|
+
before { allow(env).to receive(:tmp_path).and_return(Pathname.new(some_dir)) }
|
280
|
+
|
281
|
+
it { expect(env.pid_path).to eq Pathname.new("#{some_dir}/#{Digest::MD5.hexdigest(tty)}.pid") }
|
282
|
+
end
|
283
|
+
end
|
@@ -28,7 +28,7 @@ RSpec.describe Hrk::Execute::Command do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'interactions' do
|
31
|
-
before { command.call
|
31
|
+
before { command.call(opt, remote, *args) }
|
32
32
|
|
33
33
|
it { expect(Hrk::Heroku).to have_received(:new).with(opt, remote) }
|
34
34
|
it { expect(heroku).to have_received(:call).with(*%w{whatever that:may -b}) }
|
@@ -46,9 +46,9 @@ RSpec.describe Hrk::Execute::Command do
|
|
46
46
|
|
47
47
|
it { expect { command.call }.to raise_error ArgumentError }
|
48
48
|
it { expect { command.call "parameterless-remote", *other_args }.to raise_error ArgumentError }
|
49
|
-
it { expect { command.call
|
50
|
-
it { expect { command.call
|
51
|
-
it { expect { command.call
|
49
|
+
it { expect { command.call(*other_args) }.to raise_error ArgumentError }
|
50
|
+
it { expect { command.call(*other_args, '-r') }.to raise_error ArgumentError }
|
51
|
+
it { expect { command.call(*other_args, '-a') }.to raise_error ArgumentError }
|
52
52
|
it { expect { command.call '-r', 'remote', *other_args, '-r', 'other-remote' }.to raise_error ArgumentError }
|
53
53
|
it { expect { command.call '-r', 'remote', *other_args, '-a', 'app' }.to raise_error ArgumentError }
|
54
54
|
it { expect { command.call '-a', 'app', *other_args, '-a', 'other-app' }.to raise_error ArgumentError }
|
@@ -94,7 +94,7 @@ RSpec.describe Hrk::Execute::Command do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
describe 'interactions' do
|
97
|
-
before { command.call
|
97
|
+
before { command.call(*args) }
|
98
98
|
|
99
99
|
it { expect(Hrk::Heroku).to have_received(:new).with('-r', previous_remote) }
|
100
100
|
it { expect(heroku).to have_received(:call).with(*%w{whatever that:may -b}) }
|
@@ -107,12 +107,12 @@ RSpec.describe Hrk::Execute::Command do
|
|
107
107
|
before { expect(heroku).not_to receive(:call) }
|
108
108
|
before { expect(command.env).not_to receive(:remote=) }
|
109
109
|
|
110
|
-
it { expect { command.call
|
111
|
-
it { expect { command.call
|
112
|
-
it { expect { command.call
|
113
|
-
it { expect { command.call
|
114
|
-
it { expect { command.call
|
115
|
-
it { expect { command.call
|
110
|
+
it { expect { command.call(*other_args, '-r') }.to raise_error ArgumentError }
|
111
|
+
it { expect { command.call(*other_args, '-a') }.to raise_error ArgumentError }
|
112
|
+
it { expect { command.call('-r', 'remote', *other_args, '-r', 'other-remote') }.to raise_error ArgumentError }
|
113
|
+
it { expect { command.call('-r', 'remote', *other_args, '-a', 'app') }.to raise_error ArgumentError }
|
114
|
+
it { expect { command.call('-a', 'app', *other_args, '-a', 'other-app') }.to raise_error ArgumentError }
|
115
|
+
it { expect { command.call('-r', 'something', *other_args, '-a', 'something-else') }.to raise_error ArgumentError }
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
data/spec/hrk/execute_spec.rb
CHANGED
@@ -16,4 +16,13 @@ RSpec.describe Hrk::Execute do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
describe '.executer' do
|
21
|
+
let(:help) { double(Hrk::Execute::Help) }
|
22
|
+
let(:command) { double(Hrk::Execute::Command) }
|
23
|
+
before { allow(Hrk::Execute::Help).to receive(:new).with(command).and_return(help) }
|
24
|
+
before { allow(Hrk::Execute::Command).to receive(:new).and_return(command) }
|
25
|
+
|
26
|
+
it { expect(Hrk::Execute.executer).to eq help }
|
27
|
+
end
|
19
28
|
end
|
data/spec/hrk/heroku_spec.rb
CHANGED
@@ -7,7 +7,7 @@ RSpec.describe Hrk::Heroku do
|
|
7
7
|
describe "calling '#{command.join ' '}' on remote '#{on_remote}', system" do
|
8
8
|
subject(:heroku) { Hrk::Heroku.new(*on_remote) }
|
9
9
|
|
10
|
-
before { heroku.call
|
10
|
+
before { heroku.call(*command) }
|
11
11
|
|
12
12
|
it { expect(heroku).to have_received(:system).with(*starts) }
|
13
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hrk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Belleville
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -128,6 +128,8 @@ files:
|
|
128
128
|
- lib/hrk/execute/command.rb
|
129
129
|
- lib/hrk/execute/help.rb
|
130
130
|
- lib/hrk/heroku.rb
|
131
|
+
- lib/hrk/version.rb
|
132
|
+
- spec/hrk/env_spec.rb
|
131
133
|
- spec/hrk/execute/command_spec.rb
|
132
134
|
- spec/hrk/execute/help_spec.rb
|
133
135
|
- spec/hrk/execute_spec.rb
|
@@ -156,5 +158,5 @@ rubyforge_project:
|
|
156
158
|
rubygems_version: 2.2.2
|
157
159
|
signing_key:
|
158
160
|
specification_version: 4
|
159
|
-
summary: Hrk remembers your heroku remotes
|
161
|
+
summary: Hrk remembers your heroku remotes for you.
|
160
162
|
test_files: []
|