From 84b47360b21432648eb1556cd968337acb292656 Mon Sep 17 00:00:00 2001 From: Pete Doherty Date: Sat, 26 May 2018 13:24:22 -0400 Subject: [PATCH] Use Correct Project Config File Path When Generating Config File * 440-fix-config-file-path-in-project-config - use full project config file path when generating project config file * MISC - refactor "should always generate a project file" spec -- use Dir.mktmpdir * 440-fix-config-file-path-in-project-config - update CHANGELOG.md Closes #440. --- CHANGELOG.md | 1 + lib/tmuxinator/assets/sample.yml | 2 +- spec/lib/tmuxinator/cli_spec.rb | 31 ++++++++++++++++++------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8067394..6efcf7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Unreleased +- use correct paths in generated config file comment (#440) - fix "wrong namespace" RuboCop warnings (#620) ## 0.11.2 diff --git a/lib/tmuxinator/assets/sample.yml b/lib/tmuxinator/assets/sample.yml index 8f9b73e..d73934a 100644 --- a/lib/tmuxinator/assets/sample.yml +++ b/lib/tmuxinator/assets/sample.yml @@ -1,4 +1,4 @@ -# ~/.tmuxinator/<%= name %>.yml +# <%= path %> name: <%= name %> root: ~/ diff --git a/spec/lib/tmuxinator/cli_spec.rb b/spec/lib/tmuxinator/cli_spec.rb index 6694d45..ae116ae 100644 --- a/spec/lib/tmuxinator/cli_spec.rb +++ b/spec/lib/tmuxinator/cli_spec.rb @@ -638,21 +638,26 @@ describe Tmuxinator::Cli do end describe "#generate_project_file" do - let(:name) { "foobar" } - let(:path) { Tmuxinator::Config.default_project(name) } - - before do - expect(File).not_to exist(path), "expected file at #{path} not to exist" - end - - after(:each) do - FileUtils.remove_file(path) if File.exist?(path) - end + let(:name) { "foobar-#{Time.now.to_i}" } it "should always generate a project file" do - new_path = Tmuxinator::Cli.new.generate_project_file(name, path) - expect(new_path).to eq path - expect(File).to exist new_path + Dir.mktmpdir do |dir| + path = "#{dir}/#{name}.yml" + expect(File).not_to exist(path), "expected file at #{path} not to exist" + new_path = Tmuxinator::Cli.new.generate_project_file(name, path) + expect(new_path).to eq path + expect(File).to exist new_path + end + end + + it "should generate a project file using the correct project file path" do + file = StringIO.new + allow(File).to receive(:open) { |&block| block.yield file } + Dir.mktmpdir do |dir| + path = "#{dir}/#{name}.yml" + _ = Tmuxinator::Cli.new.generate_project_file(name, path) + expect(file.string).to match %r{\A# #{path}$} + end end end