Skip to content

Commit

Permalink
add support for local project configs using the .yaml extension (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethagnawl committed Jun 14, 2021
1 parent a72b64f commit 68a508a
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## Unreleased
### Misc
- add support for local project configs using the .yaml extension

## 3.0.0
### Misc
- Deprecate Ruby 2.5; bump min Ruby version in gemspec; bump Ruby versions in Travis test matrix
Expand Down
4 changes: 2 additions & 2 deletions lib/tmuxinator/cli.rb
Expand Up @@ -21,7 +21,7 @@ def self.exit_on_failure?
for project reuse) or a path to a project config file (via the -p flag)
}.join(" "),
stop: "Stop a tmux session using a project's tmuxinator config",
local: "Start a tmux session using ./.tmuxinator.yml",
local: "Start a tmux session using ./.tmuxinator.y[a]ml",
debug: "Output the shell commands that are generated by tmuxinator",
copy: %w{
Copy an existing project to a new project and
Expand Down Expand Up @@ -160,7 +160,7 @@ def find_project_file(name, local = false)

def config_path(name, local = false)
if local
Tmuxinator::Config::LOCAL_DEFAULT
Tmuxinator::Config::LOCAL_DEFAULTS[0]
else
Tmuxinator::Config.default_project(name)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tmuxinator/config.rb
@@ -1,6 +1,6 @@
module Tmuxinator
class Config
LOCAL_DEFAULT = "./.tmuxinator.yml".freeze
LOCAL_DEFAULTS = ["./.tmuxinator.yml", "./.tmuxinator.yaml"].freeze
NO_LOCAL_FILE_MSG =
"Project file at ./.tmuxinator.yml doesn't exist.".freeze
NO_PROJECT_FOUND_MSG = "Project could not be found.".freeze
Expand Down Expand Up @@ -94,7 +94,7 @@ def global_project(name)
end

def local_project
[LOCAL_DEFAULT].detect { |f| File.exist?(f) }
LOCAL_DEFAULTS.detect { |f| File.exist?(f) }
end

def default_project(name)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tmuxinator/cli_spec.rb
Expand Up @@ -501,7 +501,7 @@
end

context "file exists" do
let(:path) { Tmuxinator::Config::LOCAL_DEFAULT }
let(:path) { Tmuxinator::Config::LOCAL_DEFAULTS[0] }
before do
expect(File).to receive(:exist?).with(path) { true }
end
Expand Down
53 changes: 40 additions & 13 deletions spec/lib/tmuxinator/config_spec.rb
Expand Up @@ -213,12 +213,14 @@

describe "#default?" do
let(:directory) { described_class.directory }
let(:local_default) { described_class::LOCAL_DEFAULT }
let(:local_yml_default) { described_class::LOCAL_DEFAULTS[0] }
let(:local_yaml_default) { described_class::LOCAL_DEFAULTS[1] }
let(:proj_default) { described_class.default }

context "when the file exists" do
before do
allow(File).to receive(:exist?).with(local_default) { false }
allow(File).to receive(:exist?).with(local_yml_default) { false }
allow(File).to receive(:exist?).with(local_yaml_default) { false }
allow(File).to receive(:exist?).with(proj_default) { true }
end

Expand All @@ -229,7 +231,8 @@

context "when the file doesn't exist" do
before do
allow(File).to receive(:exist?).with(local_default) { false }
allow(File).to receive(:exist?).with(local_yml_default) { false }
allow(File).to receive(:exist?).with(local_yaml_default) { false }
allow(File).to receive(:exist?).with(proj_default) { false }
end

Expand Down Expand Up @@ -309,14 +312,14 @@

describe "#local?" do
it "checks if the given project exists" do
path = described_class::LOCAL_DEFAULT
path = described_class::LOCAL_DEFAULTS[0]
expect(File).to receive(:exist?).with(path) { true }
expect(described_class.local?).to be_truthy
end
end

describe "#local_project" do
let(:default) { described_class::LOCAL_DEFAULT }
let(:default) { described_class::LOCAL_DEFAULTS[0] }

context "with a project yml" do
it "gets the project as path to the yml file" do
Expand All @@ -334,7 +337,7 @@

describe "#project" do
let(:directory) { described_class.directory }
let(:default) { described_class::LOCAL_DEFAULT }
let(:default) { described_class::LOCAL_DEFAULTS[0] }

context "with an non-local project yml" do
before do
Expand Down Expand Up @@ -363,7 +366,8 @@
end

describe "#validate" do
let(:default) { described_class::LOCAL_DEFAULT }
let(:local_yml_default) { described_class::LOCAL_DEFAULTS[0] }
let(:local_yaml_default) { described_class::LOCAL_DEFAULTS[1] }

context "when a project config file is provided" do
it "should raise if the project config file can't be found" do
Expand Down Expand Up @@ -412,19 +416,42 @@

context "when no project name is provided" do
it "should raise if the local project file doesn't exist" do
expect(File).to receive(:exist?).with(default) { false }
expect(File).to receive(:exist?).with(local_yml_default) { false }
expect(File).to receive(:exist?).with(local_yaml_default) { false }
expect do
described_class.validate
end.to raise_error RuntimeError, %r{Project.+doesn't.exist}
end

it "should load and validate the project" do
content = File.read(File.join(fixtures_dir, "sample.yml"))
context "and tmuxinator.yml exists" do
it "should load and validate the local project" do
content = File.read(File.join(fixtures_dir, "sample.yml"))

expect(File).to receive(:exist?).with(default).at_least(:once) { true }
expect(File).to receive(:read).with(default).and_return(content)
expect(File).to receive(:exist?).
with(local_yml_default).
at_least(:once) { true }
expect(File).to receive(:read).
with(local_yml_default).
and_return(content)
expect(described_class.validate).to be_a Tmuxinator::Project
end
end

expect(described_class.validate).to be_a Tmuxinator::Project
context "and tmuxinator.yaml exists" do
it "should load and validate the local project" do
content = File.read(File.join(fixtures_dir, "sample.yml"))

expect(File).to receive(:exist?).
with(local_yml_default).
at_least(:once) { false }
expect(File).to receive(:exist?).
with(local_yaml_default).
at_least(:once) { true }
expect(File).to receive(:read).
with(local_yaml_default).
and_return(content)
expect(described_class.validate).to be_a Tmuxinator::Project
end
end
end

Expand Down

0 comments on commit 68a508a

Please sign in to comment.