tmuxinator 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 079c5def07857f7b54737cd711899a7c529fee96
4
- data.tar.gz: 461725febed6618763f593eec2952cbce8866368
3
+ metadata.gz: 7c6ff68dfeab85d67f1fb06a8e000c2bf527bd13
4
+ data.tar.gz: 028ba3082dc1d6a3c6108efacc2e9f130135b904
5
5
  SHA512:
6
- metadata.gz: f4860c8924f4feb57ae84f2d122a78b9680ff08b83e3e446c70c6464ced07b4e81be1e80e347a20e660d1c386f33d3a393caa585813a1d3eb78648c94c4173ec
7
- data.tar.gz: 6b05f2ad6143fd9cd4aa15318dd8e9e9dc816a7e080cb414e468977d7a0bf7d3583f58fd36fd7e981d6ebb103f7c3690b130062980beadbc37bf6728e0bfe946
6
+ metadata.gz: 6e1d74afdea6de73c488ec8f84bf14acfe01e86c6a80b1f523b0993544e208089310aeb3daa8a80eb7296791a1139f750ae0530778ad3f61bc289fd6a5b85157
7
+ data.tar.gz: d23d2b5311bdaf10b332f9533794ee781f64407fcc979d44d37541f0b00ae024d672009b7c5307e01d39adf82a89b3a9ab5af6aaae9c07fe4534a69dbb94aa4b
@@ -67,22 +67,32 @@ module Tmuxinator
67
67
  desc: "Create local project file at ./.tmuxinator.yml"
68
68
 
69
69
  def new(name)
70
- project_file = if options[:local]
71
- Tmuxinator::Config::LOCAL_DEFAULT
72
- else
73
- Tmuxinator::Config.default_project(name)
74
- end
75
- unless Tmuxinator::Config.exists?(project_file)
70
+ project_file = find_project_file(name, options[:local])
71
+ Kernel.system("$EDITOR #{project_file}") || doctor
72
+ end
73
+
74
+ no_commands do
75
+ def find_project_file(name, local = false)
76
+ path = if local
77
+ Tmuxinator::Config::LOCAL_DEFAULT
78
+ else
79
+ Tmuxinator::Config.default_project(name)
80
+ end
81
+ if File.exists?(path)
82
+ path
83
+ else
84
+ generate_project_file(name, path)
85
+ end
86
+ end
87
+
88
+ def generate_project_file(name, path)
76
89
  template = Tmuxinator::Config.default? ? :default : :sample
77
90
  content = File.read(Tmuxinator::Config.send(template.to_sym))
78
91
  erb = Erubis::Eruby.new(content).result(binding)
79
- File.open(project_file, "w") { |f| f.write(erb) }
92
+ File.open(path, "w") { |f| f.write(erb) }
93
+ path
80
94
  end
81
95
 
82
- Kernel.system("$EDITOR #{project_file}") || doctor
83
- end
84
-
85
- no_commands do
86
96
  def create_project(project_options = {})
87
97
  attach_opt = project_options[:attach]
88
98
  attach = !attach_opt.nil? && attach_opt ? true : false
@@ -1,3 +1,3 @@
1
1
  module Tmuxinator
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -149,6 +149,41 @@ describe Tmuxinator::Cli do
149
149
  end
150
150
  end
151
151
 
152
+ describe "#edit" do
153
+ let(:file) { StringIO.new }
154
+ let(:name) { "test" }
155
+ let(:path) { Tmuxinator::Config.default_project(name) }
156
+
157
+ context "when the project file _does_ already exist" do
158
+ let(:extra) { " - extra: echo 'foobar'" }
159
+
160
+ before do
161
+ # make sure that no project file exists initially
162
+ FileUtils.remove_file(path) if File.exists?(path)
163
+ expect(File).not_to exist(path)
164
+
165
+ # now generate a project file
166
+ expect(Tmuxinator::Cli.new.generate_project_file(name, path)).to eq path
167
+ expect(File).to exist path
168
+
169
+ # add some content to the project file
170
+ File.open(path, "w") do |f|
171
+ f.write(extra)
172
+ f.flush
173
+ end
174
+ expect(File.read(path)).to match %r{#{extra}}
175
+
176
+ # get ready to run `tmuxinator edit #{name}`
177
+ ARGV.replace ["edit", name]
178
+ end
179
+
180
+ it "should _not_ generate a new project file" do
181
+ capture_io { cli.start }
182
+ expect(File.read(path)).to match %r{#{extra}}
183
+ end
184
+ end
185
+ end
186
+
152
187
  describe "#new" do
153
188
  let(:file) { StringIO.new }
154
189
  let(:name) { "test" }
@@ -164,7 +199,7 @@ describe Tmuxinator::Cli do
164
199
 
165
200
  context "existing project doesn't exist" do
166
201
  before do
167
- expect(Tmuxinator::Config).to receive_messages(exists?: false)
202
+ expect(File).to receive_messages(exists?: false)
168
203
  end
169
204
 
170
205
  it "creates a new tmuxinator project file" do
@@ -174,14 +209,15 @@ describe Tmuxinator::Cli do
174
209
  end
175
210
 
176
211
  context "files exists" do
177
- let(:command) { "#{ENV['HOME']}\/\.tmuxinator\/#{name}\.yml" }
212
+ let(:root_path) { "#{ENV['HOME']}\/\.tmuxinator\/#{name}\.yml" }
178
213
 
179
214
  before do
180
- expect(Tmuxinator::Config).to receive_messages(exists?: true)
215
+ allow(File).to receive(:exists?).with(anything).and_return(false)
216
+ expect(File).to receive(:exists?).with(root_path).and_return(true)
181
217
  end
182
218
 
183
219
  it "just opens the file" do
184
- expect(Kernel).to receive(:system).with(%r{#{command}})
220
+ expect(Kernel).to receive(:system).with(%r{#{root_path}})
185
221
  capture_io { cli.start }
186
222
  end
187
223
  end
@@ -194,7 +230,7 @@ describe Tmuxinator::Cli do
194
230
 
195
231
  context "existing project doesn't exist" do
196
232
  before do
197
- expect(Tmuxinator::Config).to receive(:exists?).at_least(:once) do
233
+ allow(File).to receive(:exists?).at_least(:once) do
198
234
  false
199
235
  end
200
236
  end
@@ -208,7 +244,7 @@ describe Tmuxinator::Cli do
208
244
  context "files exists" do
209
245
  let(:path) { Tmuxinator::Config::LOCAL_DEFAULT }
210
246
  before do
211
- expect(Tmuxinator::Config).to receive(:exists?).with(path) { true }
247
+ expect(File).to receive(:exists?).with(path) { true }
212
248
  end
213
249
 
214
250
  it "just opens the file" do
@@ -368,6 +404,69 @@ describe Tmuxinator::Cli do
368
404
  end
369
405
  end
370
406
 
407
+ describe "#find_project_file" do
408
+ let(:name) { "foobar" }
409
+ let(:path) { Tmuxinator::Config.default_project(name) }
410
+
411
+ after(:each) do
412
+ FileUtils.remove_file(path) if File.exists?(path)
413
+ end
414
+
415
+ context "when the project file does not already exist" do
416
+ before do
417
+ expect(File).not_to exist(path), "expected file at #{path} not to exist"
418
+ end
419
+
420
+ it "should generate a project file" do
421
+ new_path = Tmuxinator::Cli.new.find_project_file(name, false)
422
+ expect(new_path).to eq path
423
+ expect(File).to exist new_path
424
+ end
425
+ end
426
+
427
+ context "when the project file _does_ already exist" do
428
+ let(:extra) { " - extra: echo 'foobar'" }
429
+
430
+ before do
431
+ expect(File).not_to exist(path), "expected file at #{path} not to exist"
432
+ expect(Tmuxinator::Cli.new.generate_project_file(name, path)).to eq path
433
+ expect(File).to exist path
434
+
435
+ File.open(path, "w") do |f|
436
+ f.write(extra)
437
+ f.flush
438
+ end
439
+ expect(File.read(path)).to match %r{#{extra}}
440
+ end
441
+
442
+ it "should _not_ generate a new project file" do
443
+ new_path = Tmuxinator::Cli.new.find_project_file(name, false)
444
+ expect(new_path).to eq path
445
+ expect(File).to exist new_path
446
+ expect(File.read(new_path)).to match %r{#{extra}}
447
+ end
448
+ end
449
+ end
450
+
451
+ describe "#generate_project_file" do
452
+ let(:name) { "foobar" }
453
+ let(:path) { Tmuxinator::Config.default_project(name) }
454
+
455
+ before do
456
+ expect(File).not_to exist(path), "expected file at #{path} not to exist"
457
+ end
458
+
459
+ after(:each) do
460
+ FileUtils.remove_file(path) if File.exists?(path)
461
+ end
462
+
463
+ it "should always generate a project file" do
464
+ new_path = Tmuxinator::Cli.new.generate_project_file(name, path)
465
+ expect(new_path).to eq path
466
+ expect(File).to exist new_path
467
+ end
468
+ end
469
+
371
470
  describe "#create_project" do
372
471
  shared_examples_for :a_proper_project do
373
472
  it "should create a valid project" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmuxinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Bargi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-10 00:00:00.000000000 Z
12
+ date: 2015-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: 1.8.23
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.4.5.1
133
+ rubygems_version: 2.4.2
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Create and manage complex tmux sessions easily.