tmuxinator 0.6.11 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,27 @@ require "spec_helper"
2
2
 
3
3
  describe Tmuxinator::Project do
4
4
  let(:project) { FactoryGirl.build(:project) }
5
- let(:project_with_custom_name) { FactoryGirl.build(:project_with_custom_name) }
6
- let(:project_with_deprecations) { FactoryGirl.build(:project_with_deprecations) }
5
+ let(:project_with_custom_name) do
6
+ FactoryGirl.build(:project_with_custom_name)
7
+ end
8
+ let(:project_with_number_as_name) do
9
+ FactoryGirl.build(:project_with_number_as_name)
10
+ end
11
+ let(:project_with_deprecations) do
12
+ FactoryGirl.build(:project_with_deprecations)
13
+ end
14
+ let(:project_with_force_attach) do
15
+ FactoryGirl.build(:project_with_force_attach)
16
+ end
17
+ let(:project_with_force_detach) do
18
+ FactoryGirl.build(:project_with_force_detach)
19
+ end
20
+
7
21
  let(:wemux_project) { FactoryGirl.build(:wemux_project) }
8
22
  let(:noname_project) { FactoryGirl.build(:noname_project) }
23
+ let(:nameless_window_project) do
24
+ FactoryGirl.build(:nameless_window_project)
25
+ end
9
26
 
10
27
  describe "#initialize" do
11
28
  context "valid yaml" do
@@ -65,7 +82,7 @@ describe Tmuxinator::Project do
65
82
 
66
83
  context "without root" do
67
84
  it "doesn't throw an error" do
68
- expect{noname_project.root}.to_not raise_error
85
+ expect { noname_project.root }.to_not raise_error
69
86
  end
70
87
  end
71
88
  end
@@ -91,7 +108,14 @@ describe Tmuxinator::Project do
91
108
 
92
109
  context "without name" do
93
110
  it "displays error message" do
94
- expect{noname_project.name}.to_not raise_error
111
+ expect { noname_project.name }.to_not raise_error
112
+ end
113
+ end
114
+
115
+ context "as number" do
116
+ it "will gracefully handle a name given as a number" do
117
+ rendered = project_with_number_as_name
118
+ expect(rendered.name.to_i).to_not equal 0
95
119
  end
96
120
  end
97
121
  end
@@ -104,8 +128,9 @@ describe Tmuxinator::Project do
104
128
  context "with deprecations" do
105
129
  context "rbenv option is present" do
106
130
  before do
107
- allow(project).to receive_messages(:rbenv? => true)
108
- allow(project).to receive_message_chain(:yaml, :[]).and_return("2.0.0-p247")
131
+ allow(project).to receive_messages(rbenv?: true)
132
+ allow(project).to \
133
+ receive_message_chain(:yaml, :[]).and_return("2.0.0-p247")
109
134
  end
110
135
 
111
136
  it "still gets the correct pre_window command" do
@@ -115,8 +140,9 @@ describe Tmuxinator::Project do
115
140
 
116
141
  context "rvm option is present" do
117
142
  before do
118
- allow(project).to receive_messages(:rbenv? => false)
119
- allow(project).to receive_message_chain(:yaml, :[]).and_return("ruby-2.0.0-p247")
143
+ allow(project).to receive_messages(rbenv?: false)
144
+ allow(project).to \
145
+ receive_message_chain(:yaml, :[]).and_return("ruby-2.0.0-p247")
120
146
  end
121
147
 
122
148
  it "still gets the correct pre_window command" do
@@ -126,8 +152,8 @@ describe Tmuxinator::Project do
126
152
 
127
153
  context "pre_tab is present" do
128
154
  before do
129
- allow(project).to receive_messages(:rbenv? => false)
130
- allow(project).to receive_messages(:pre_tab? => true)
155
+ allow(project).to receive_messages(rbenv?: false)
156
+ allow(project).to receive_messages(pre_tab?: true)
131
157
  end
132
158
 
133
159
  it "still gets the correct pre_window command" do
@@ -140,7 +166,7 @@ describe Tmuxinator::Project do
140
166
  describe "#socket" do
141
167
  context "socket path is present" do
142
168
  before do
143
- allow(project).to receive_messages(:socket_path => "/tmp")
169
+ allow(project).to receive_messages(socket_path: "/tmp")
144
170
  end
145
171
 
146
172
  it "gets the socket path" do
@@ -170,7 +196,7 @@ describe Tmuxinator::Project do
170
196
  describe "#tmux_options" do
171
197
  context "no tmux options" do
172
198
  before do
173
- allow(project).to receive_messages(:tmux_options? => false)
199
+ allow(project).to receive_messages(tmux_options?: false)
174
200
  end
175
201
 
176
202
  it "returns nothing" do
@@ -180,18 +206,20 @@ describe Tmuxinator::Project do
180
206
 
181
207
  context "with deprecations" do
182
208
  before do
183
- allow(project_with_deprecations).to receive_messages(:cli_args? => true)
209
+ allow(project_with_deprecations).to receive_messages(cli_args?: true)
184
210
  end
185
211
 
186
212
  it "still gets the tmux options" do
187
- expect(project_with_deprecations.tmux_options).to eq " -f ~/.tmux.mac.conf"
213
+ expect(project_with_deprecations.tmux_options).to \
214
+ eq " -f ~/.tmux.mac.conf"
188
215
  end
189
216
  end
190
217
  end
191
218
 
192
219
  describe "#get_pane_base_index" do
193
220
  it "extracts the pane_base_index from tmux_options" do
194
- allow(project).to receive_messages(show_tmux_options: tmux_config(pane_base_index: 3))
221
+ allow(project).to \
222
+ receive_messages(show_tmux_options: tmux_config(pane_base_index: 3))
195
223
 
196
224
  expect(project.get_pane_base_index).to eq("3")
197
225
  end
@@ -199,7 +227,8 @@ describe Tmuxinator::Project do
199
227
 
200
228
  describe "#get_base_index" do
201
229
  it "extracts the base index from options" do
202
- allow(project).to receive_messages(show_tmux_options: tmux_config(base_index: 1))
230
+ allow(project).to \
231
+ receive_messages(show_tmux_options: tmux_config(base_index: 1))
203
232
 
204
233
  expect(project.get_base_index).to eq("1")
205
234
  end
@@ -208,8 +237,8 @@ describe Tmuxinator::Project do
208
237
  describe "#base_index" do
209
238
  context "pane base index present" do
210
239
  before do
211
- allow(project).to receive_messages(:get_pane_base_index => "1")
212
- allow(project).to receive_messages(:get_base_index => "1")
240
+ allow(project).to receive_messages(get_pane_base_index: "1")
241
+ allow(project).to receive_messages(get_base_index: "1")
213
242
  end
214
243
 
215
244
  it "gets the pane base index" do
@@ -219,8 +248,8 @@ describe Tmuxinator::Project do
219
248
 
220
249
  context "pane base index no present" do
221
250
  before do
222
- allow(project).to receive_messages(:get_pane_base_index => nil)
223
- allow(project).to receive_messages(:get_base_index => "0")
251
+ allow(project).to receive_messages(get_pane_base_index: nil)
252
+ allow(project).to receive_messages(get_base_index: "0")
224
253
  end
225
254
 
226
255
  it "gets the base index" do
@@ -234,15 +263,15 @@ describe Tmuxinator::Project do
234
263
  it "gets the startup window from project config" do
235
264
  project.yaml["startup_window"] = "logs"
236
265
 
237
- expect(project.startup_window).to eq("logs")
266
+ expect(project.startup_window).to eq("logs")
238
267
  end
239
268
  end
240
269
 
241
270
  context "startup window not specified" do
242
271
  it "returns base index instead" do
243
- allow(project).to receive_messages(:base_index => 8)
272
+ allow(project).to receive_messages(base_index: 8)
244
273
 
245
- expect(project.startup_window).to eq 8
274
+ expect(project.startup_window).to eq 8
246
275
  end
247
276
  end
248
277
  end
@@ -286,7 +315,8 @@ describe Tmuxinator::Project do
286
315
 
287
316
  context "command for window is not empty" do
288
317
  it "returns the tmux command" do
289
- expect(project.send_keys("vim", 1)).to eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m"
318
+ expect(project.send_keys("vim", 1)).to \
319
+ eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m"
290
320
  end
291
321
  end
292
322
  end
@@ -300,7 +330,8 @@ describe Tmuxinator::Project do
300
330
 
301
331
  context "command for pane is not empty" do
302
332
  it "returns the tmux command" do
303
- expect(project.send_pane_command("vim", 1, 0)).to eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m"
333
+ expect(project.send_pane_command("vim", 1, 0)).to \
334
+ eq "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 vim C-m"
304
335
  end
305
336
  end
306
337
  end
@@ -323,7 +354,11 @@ describe Tmuxinator::Project do
323
354
  let(:window) { project.windows.keep_if { |w| w.name == "shell" }.first }
324
355
 
325
356
  it "splits commands into an array" do
326
- expect(window.commands).to eq(["tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ pull C-m", "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ merge C-m"])
357
+ commands = [
358
+ "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ pull C-m",
359
+ "tmux -f ~/.tmux.mac.conf -L foo send-keys -t sample:1 git\\ merge C-m"
360
+ ]
361
+ expect(window.commands).to eq(commands)
327
362
  end
328
363
  end
329
364
 
@@ -339,16 +374,125 @@ describe Tmuxinator::Project do
339
374
  end
340
375
 
341
376
  context "pre in yaml is Array" do
342
- before {
377
+ before do
343
378
  project.yaml["pre"] = [
344
379
  "mysql.server start",
345
380
  "memcached -d"
346
381
  ]
347
- }
382
+ end
348
383
 
349
384
  it "joins array using ;" do
350
385
  expect(pre).to eq("mysql.server start; memcached -d")
351
386
  end
352
387
  end
353
388
  end
389
+
390
+ describe "#attach?" do
391
+ context "attach is true in yaml" do
392
+ before { project.yaml["attach"] = true }
393
+
394
+ it "returns true" do
395
+ expect(project.attach?).to be_truthy
396
+ end
397
+ end
398
+
399
+ context "attach is not defined in yaml" do
400
+ it "returns true" do
401
+ expect(project.attach?).to be_truthy
402
+ end
403
+ end
404
+
405
+ context "attach is false in yaml" do
406
+ before { project.yaml["attach"] = false }
407
+ it "returns false" do
408
+ expect(project.attach?).to be_falsey
409
+ end
410
+ end
411
+
412
+ context "attach is true in yaml, but command line forces detach" do
413
+ before { project_with_force_attach.yaml["attach"] = true }
414
+
415
+ it "returns false" do
416
+ expect(project_with_force_detach.attach?).to be_falsey
417
+ end
418
+ end
419
+
420
+ context "attach is false in yaml, but command line forces attach" do
421
+ before { project_with_force_detach.yaml["attach"] = false }
422
+
423
+ it "returns true" do
424
+ expect(project_with_force_attach.attach?).to be_truthy
425
+ end
426
+ end
427
+ end
428
+
429
+ describe "tmux_new_session_command" do
430
+ let(:command) { "#{executable} new-session -d -s #{session} -n #{window}" }
431
+ let(:executable) { project.tmux }
432
+ let(:session) { project.name }
433
+ let(:window) { project.windows.first.name }
434
+
435
+ context "when first window has a name" do
436
+ it "returns command to start a new detatched session" do
437
+ expect(project.tmux_new_session_command).to eq command
438
+ end
439
+ end
440
+
441
+ context "when first window is nameless" do
442
+ let(:project) { nameless_window_project }
443
+ let(:command) { "#{project.tmux} new-session -d -s #{project.name} " }
444
+
445
+ it "returns command to for new detatched session without a window name" do
446
+ expect(project.tmux_new_session_command).to eq command
447
+ end
448
+ end
449
+ end
450
+
451
+ describe "::load" do
452
+ let(:path) { File.expand_path("../../../fixtures/sample.yml", __FILE__) }
453
+ let(:options) { {} }
454
+
455
+ it "should raise if the project file doesn't parse" do
456
+ bad_yaml = <<-Y
457
+ name: "foo"
458
+ subkey:
459
+ Y
460
+ expect(File).to receive(:read).with(path) { bad_yaml }
461
+ expect do
462
+ described_class.load(path, options)
463
+ end.to raise_error RuntimeError, %r{Failed.to.parse.config.file}
464
+ end
465
+
466
+ it "should return an instance of the class if the file loads" do
467
+ expect(described_class.load(path, options)).to be_a Tmuxinator::Project
468
+ end
469
+ end
470
+
471
+ describe "::parse_settings" do
472
+ let(:args) { ["one", "two=three"] }
473
+
474
+ it "returns settings in a hash" do
475
+ expect(described_class.parse_settings(args)["two"]).to eq("three")
476
+ end
477
+
478
+ it "removes settings from args" do
479
+ described_class.parse_settings(args)
480
+ expect(args).to eq(["one"])
481
+ end
482
+ end
483
+
484
+ describe "#validate!" do
485
+ it "should raise if there are no windows defined" do
486
+ nowindows_project = FactoryGirl.build(:nowindows_project)
487
+ expect do
488
+ nowindows_project.validate!
489
+ end.to raise_error RuntimeError, %r{should.include.some.windows}
490
+ end
491
+
492
+ it "should raise if there is not a project name" do
493
+ expect do
494
+ noname_project.validate!
495
+ end.to raise_error RuntimeError, %r{didn't.specify.a.'project_name'}
496
+ end
497
+ end
354
498
  end
@@ -2,5 +2,4 @@ require "spec_helper"
2
2
 
3
3
  describe Tmuxinator::Util do
4
4
  let(:util) { Object.new.extend(Tmuxinator::Util) }
5
-
6
5
  end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe Tmuxinator::WemuxSupport do
4
+ let(:klass) { Class.new { include Tmuxinator::WemuxSupport } }
5
+ let(:instance) { klass.new }
6
+
7
+ it { expect(instance).to respond_to :wemux? }
8
+ it { expect(instance).to respond_to :load_wemux_overrides }
9
+
10
+ describe "#load_wemux_overrides" do
11
+ before { instance.load_wemux_overrides }
12
+
13
+ it "adds a render method" do
14
+ expect(instance).to respond_to :render
15
+ end
16
+
17
+ it "adds a name method" do
18
+ expect(instance).to respond_to :name
19
+ end
20
+
21
+ it "adds a tmux method" do
22
+ expect(instance).to respond_to :tmux
23
+ end
24
+ end
25
+
26
+ describe "#render" do
27
+ before { instance.load_wemux_overrides }
28
+
29
+ it "renders the template" do
30
+ expect(File).to receive(:read).at_least(:once) { "wemux ls 2>/dev/null" }
31
+
32
+ expect(instance.render).to match %r{wemux.ls.2>\/dev\/null}
33
+ end
34
+ end
35
+
36
+ describe "#name" do
37
+ before { instance.load_wemux_overrides }
38
+
39
+ it { expect(instance.name).to eq "wemux" }
40
+ end
41
+
42
+ describe "#tmux" do
43
+ before { instance.load_wemux_overrides }
44
+
45
+ it { expect(instance.tmux).to eq "wemux" }
46
+ end
47
+ end
@@ -3,10 +3,14 @@ require "spec_helper"
3
3
  describe Tmuxinator::Window do
4
4
  let(:project) { double }
5
5
  let(:panes) { ["vim", nil, "top"] }
6
+ let(:window_name) { "editor" }
6
7
  let(:yaml) do
7
8
  {
8
- "editor" => {
9
- "pre" => ["echo 'I get run in each pane. Before each pane command!'", nil],
9
+ window_name => {
10
+ "pre" => [
11
+ "echo 'I get run in each pane. Before each pane command!'",
12
+ nil
13
+ ],
10
14
  "layout" => "main-vertical",
11
15
  "panes" => panes
12
16
  }
@@ -17,7 +21,10 @@ describe Tmuxinator::Window do
17
21
  "editor" => {
18
22
  "root" => "/project/override",
19
23
  "root?" => true,
20
- "pre" => ["echo 'I get run in each pane. Before each pane command!'", nil],
24
+ "pre" => [
25
+ "echo 'I get run in each pane. Before each pane command!'",
26
+ nil
27
+ ],
21
28
  "layout" => "main-vertical",
22
29
  "panes" => panes
23
30
  }
@@ -29,12 +36,12 @@ describe Tmuxinator::Window do
29
36
 
30
37
  before do
31
38
  allow(project).to receive_messages(
32
- :tmux => "tmux",
33
- :name => "test",
34
- :base_index => 1,
35
- :root => "/project/tmuxinator",
36
- :root? => true
37
- )
39
+ tmux: "tmux",
40
+ name: "test",
41
+ base_index: 1,
42
+ root: "/project/tmuxinator",
43
+ root?: true
44
+ )
38
45
  end
39
46
 
40
47
  describe "#initialize" do
@@ -61,7 +68,7 @@ describe Tmuxinator::Window do
61
68
  let(:pane) { double(:pane) }
62
69
 
63
70
  before do
64
- allow(Tmuxinator::Pane).to receive_messages :new => pane
71
+ allow(Tmuxinator::Pane).to receive_messages new: pane
65
72
  end
66
73
 
67
74
  context "with a three element Array" do
@@ -133,7 +140,10 @@ describe Tmuxinator::Window do
133
140
  end
134
141
 
135
142
  it "returns the flattened command" do
136
- expect(window.commands).to eq ["tmux send-keys -t test:1 git\\ fetch C-m", "tmux send-keys -t test:1 git\\ status C-m"]
143
+ expect(window.commands).to eq [
144
+ "tmux send-keys -t test:1 git\\ fetch C-m",
145
+ "tmux send-keys -t test:1 git\\ status C-m"
146
+ ]
137
147
  end
138
148
  end
139
149
 
@@ -158,27 +168,78 @@ describe Tmuxinator::Window do
158
168
  end
159
169
  end
160
170
 
171
+ describe "#name_options" do
172
+ context "with a name" do
173
+ let(:window_name) { "editor" }
174
+
175
+ it "specifies name with tmux name option" do
176
+ expect(window.tmux_window_name_option).to eq "-n #{window_name}"
177
+ end
178
+ end
179
+
180
+ context "without a name" do
181
+ let(:window_name) { nil }
182
+
183
+ it "specifies no tmux name option" do
184
+ expect(window.tmux_window_name_option).to be_empty
185
+ end
186
+ end
187
+ end
188
+
161
189
  describe "#tmux_new_window_command" do
162
190
  let(:project) { double(:project) }
163
191
  let(:window) { Tmuxinator::Window.new(yaml, 0, project) }
192
+ let(:root?) { true }
193
+ let(:root) { "/project/tmuxinator" }
164
194
 
165
195
  before do
166
196
  allow(project).to receive_messages(
167
- :name => "",
168
- :tmux => "tmux",
169
- :root => "/project/tmuxinator",
170
- :root? => true,
171
- :base_index => 1
197
+ name: "test",
198
+ tmux: "tmux",
199
+ root: root,
200
+ root?: root?,
201
+ base_index: 1
172
202
  )
173
203
  end
174
204
 
175
- context "tmux 1.6 and below" do
176
- before do
177
- allow(Tmuxinator::Config).to receive_messages(:version => 1.6)
205
+ let(:tmux_part) { project.tmux }
206
+ let(:window_part) { "new-window" }
207
+ let(:name_part) { window.tmux_window_name_option }
208
+ let(:target_part) { "-t #{window.tmux_window_target}" }
209
+ let(:path_part) { "#{path_option} #{project.root}" }
210
+
211
+ let(:path_option) { "-c" }
212
+ let(:full_command) do
213
+ "#{tmux_part} #{window_part} #{path_part} #{target_part} #{name_part}"
214
+ end
215
+
216
+ before do
217
+ allow(Tmuxinator::Config).to receive(:default_path_option) { path_option }
218
+ end
219
+
220
+ it "contstructs window command with path, target, and name options" do
221
+ expect(window.tmux_new_window_command).to eq full_command
222
+ end
223
+
224
+ context "root not set" do
225
+ let(:root?) { false }
226
+ let(:root) { nil }
227
+
228
+ let(:path_part) { nil }
229
+
230
+ it "has an extra space instead of path_part" do
231
+ expect(window.tmux_new_window_command).to eq full_command
232
+ end
233
+ end
234
+
235
+ context "name not set" do
236
+ let(:window_name) { nil }
237
+ let(:full_command) do
238
+ "#{tmux_part} #{window_part} #{path_part} #{target_part} "
178
239
  end
179
240
 
180
- it "specifies root path by passing default-path to tmux" do
181
- expect(window.tmux_new_window_command).to include("default-path /project/tmuxinator")
241
+ it "does not set name option" do
242
+ expect(window.tmux_new_window_command).to eq full_command
182
243
  end
183
244
  end
184
245
  end