From 06ec279ad1f811c97d67a743bfd576995545eb13 Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Thu, 24 Feb 2022 21:06:14 +0000 Subject: [PATCH 1/8] Failing spec as part of create command --- spec/command/create_spec.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spec/command/create_spec.rb diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb new file mode 100644 index 00000000..e249a211 --- /dev/null +++ b/spec/command/create_spec.rb @@ -0,0 +1,36 @@ +require File.expand_path('../../spec_helper', __FILE__) + +module Xcodeproj + class Command + class Create < Command + self.arguments = [ + CLAide::Argument.new('PROJECT', true), + ] + + def initialize(argv) + self.xcodeproj_path = argv.shift_argument + super + end + + def validate! + super + help! "Project file not specified" if self.xcodeproj_path.nil? + end + end + end +end + + +describe Xcodeproj::Command::Create do + it 'errors if a project file has not been provided' do + argv = CLAide::ARGV.new([]) + create = Xcodeproj::Command::Create.new(argv) + should_raise_help 'Project file not specified' do + create.validate! + end + end + + it 'errors if the specified project file already exists' + + it 'creates a project file' +end From 997efbbb007c7f93ea476853d94b0fd413a7fac3 Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:01:15 +0100 Subject: [PATCH 2/8] xcodeproject_path is reserved; ours doesn't exist yet --- spec/command/create_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index e249a211..a86adf6b 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -8,19 +8,18 @@ class Create < Command ] def initialize(argv) - self.xcodeproj_path = argv.shift_argument + @project_name = argv.shift_argument super end def validate! super - help! "Project file not specified" if self.xcodeproj_path.nil? + help! "Project file not specified" if @project_name.nil? end end end end - describe Xcodeproj::Command::Create do it 'errors if a project file has not been provided' do argv = CLAide::ARGV.new([]) From 98205fbf31884dfea0c7afbe8b89a051e69822b6 Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:10:57 +0100 Subject: [PATCH 3/8] Don't create a project if it already exists. --- spec/command/create_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index a86adf6b..2732568e 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -15,11 +15,14 @@ def initialize(argv) def validate! super help! "Project file not specified" if @project_name.nil? + help! "Project already exists" if File.exist?(@project_name) end end end end +require 'fileutils' + describe Xcodeproj::Command::Create do it 'errors if a project file has not been provided' do argv = CLAide::ARGV.new([]) @@ -29,7 +32,18 @@ def validate! end end - it 'errors if the specified project file already exists' + it 'errors if the specified project already exists' do + project_dir = 'FooBar.xcodeproj' + FileUtils.mkdir(project_dir) + + argv = CLAide::ARGV.new([project_dir]) + create = Xcodeproj::Command::Create.new(argv) + should_raise_help 'Project already exists' do + create.validate! + end + + FileUtils.rm_r(project_dir) + end it 'creates a project file' end From f95cd37ace47c26255608874bf4f150d9cdd3ecd Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:20:34 +0100 Subject: [PATCH 4/8] Create a new project. --- spec/command/create_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index 2732568e..b68cda46 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -17,6 +17,11 @@ def validate! help! "Project file not specified" if @project_name.nil? help! "Project already exists" if File.exist?(@project_name) end + + def run + project = Xcodeproj::Project.new(@project_name) + project.save + end end end end @@ -45,5 +50,14 @@ def validate! FileUtils.rm_r(project_dir) end - it 'creates a project file' + it 'creates a project file' do + project_dir = 'FooBar.xcodeproj' + argv = CLAide::ARGV.new([project_dir]) + create = Xcodeproj::Command::Create.new(argv) + create.run + + File.exist?(project_dir).should.be.true + + FileUtils.rm_r(project_dir) + end end From 9c199f2565db490c8a0a0fa22ec740cf76817bf5 Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:21:17 +0100 Subject: [PATCH 5/8] Make sure the tests always clean up after themselves. --- spec/command/create_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index b68cda46..9280dcf2 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -47,6 +47,7 @@ def run create.validate! end + ensure FileUtils.rm_r(project_dir) end @@ -58,6 +59,7 @@ def run File.exist?(project_dir).should.be.true + ensure FileUtils.rm_r(project_dir) end end From 360606761dc5cfd0aca0e31e1fa59e0e1ec255fb Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:35:03 +0100 Subject: [PATCH 6/8] Imply the extension. --- spec/command/create_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index 9280dcf2..c9572ce6 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -9,6 +9,9 @@ class Create < Command def initialize(argv) @project_name = argv.shift_argument + + add_extension_if_missing + super end @@ -22,6 +25,12 @@ def run project = Xcodeproj::Project.new(@project_name) project.save end + + def add_extension_if_missing + return unless @project_name + + @project_name += '.xcodeproj' unless File.extname(@project_name) == '.xcodeproj' + end end end end @@ -62,4 +71,16 @@ def run ensure FileUtils.rm_r(project_dir) end + + it 'adds the suffix if one is not provided' do + project_name = 'FooBar' + project_dir = 'FooBar.xcodeproj' + argv = CLAide::ARGV.new([project_name]) + create = Xcodeproj::Command::Create.new(argv) + create.run + + File.exist?(project_dir).should.be.true + ensure + FileUtils.rm_r(project_dir) + end end From 7fbd3a6ac1dc688e3382065a0fc118074b5c862a Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:37:17 +0100 Subject: [PATCH 7/8] Clean up. --- spec/command/create_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index c9572ce6..f09944c6 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -7,6 +7,8 @@ class Create < Command CLAide::Argument.new('PROJECT', true), ] + EXTENSION = '.xcodeproj' + def initialize(argv) @project_name = argv.shift_argument @@ -29,7 +31,7 @@ def run def add_extension_if_missing return unless @project_name - @project_name += '.xcodeproj' unless File.extname(@project_name) == '.xcodeproj' + @project_name += EXTENSION unless File.extname(@project_name) == EXTENSION end end end @@ -55,7 +57,6 @@ def add_extension_if_missing should_raise_help 'Project already exists' do create.validate! end - ensure FileUtils.rm_r(project_dir) end @@ -67,7 +68,6 @@ def add_extension_if_missing create.run File.exist?(project_dir).should.be.true - ensure FileUtils.rm_r(project_dir) end From 560cbeffd3e6424932f762f3950bd5e42a2cc64e Mon Sep 17 00:00:00 2001 From: "Steven R. Baker" Date: Fri, 25 Feb 2022 02:38:47 +0100 Subject: [PATCH 8/8] Put the create command into its final resting place. --- lib/xcodeproj/command.rb | 1 + lib/xcodeproj/command/create.rb | 36 ++++++++++++++++++++++++++++++++ spec/command/create_spec.rb | 37 --------------------------------- 3 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 lib/xcodeproj/command/create.rb diff --git a/lib/xcodeproj/command.rb b/lib/xcodeproj/command.rb index 90875001..661d3a8b 100644 --- a/lib/xcodeproj/command.rb +++ b/lib/xcodeproj/command.rb @@ -3,6 +3,7 @@ module Xcodeproj require 'claide' class Command < CLAide::Command + require 'xcodeproj/command/create' require 'xcodeproj/command/config_dump' require 'xcodeproj/command/target_diff' require 'xcodeproj/command/project_diff' diff --git a/lib/xcodeproj/command/create.rb b/lib/xcodeproj/command/create.rb new file mode 100644 index 00000000..cdfe37b4 --- /dev/null +++ b/lib/xcodeproj/command/create.rb @@ -0,0 +1,36 @@ +module Xcodeproj + class Command + class Create < Command + self.arguments = [ + CLAide::Argument.new('PROJECT', true), + ] + + EXTENSION = '.xcodeproj' + + def initialize(argv) + @project_name = argv.shift_argument + + add_extension_if_missing + + super + end + + def validate! + super + help! "Project file not specified" if @project_name.nil? + help! "Project already exists" if File.exist?(@project_name) + end + + def run + project = Xcodeproj::Project.new(@project_name) + project.save + end + + def add_extension_if_missing + return unless @project_name + + @project_name += EXTENSION unless File.extname(@project_name) == EXTENSION + end + end + end +end diff --git a/spec/command/create_spec.rb b/spec/command/create_spec.rb index f09944c6..d22983f5 100644 --- a/spec/command/create_spec.rb +++ b/spec/command/create_spec.rb @@ -1,42 +1,5 @@ require File.expand_path('../../spec_helper', __FILE__) -module Xcodeproj - class Command - class Create < Command - self.arguments = [ - CLAide::Argument.new('PROJECT', true), - ] - - EXTENSION = '.xcodeproj' - - def initialize(argv) - @project_name = argv.shift_argument - - add_extension_if_missing - - super - end - - def validate! - super - help! "Project file not specified" if @project_name.nil? - help! "Project already exists" if File.exist?(@project_name) - end - - def run - project = Xcodeproj::Project.new(@project_name) - project.save - end - - def add_extension_if_missing - return unless @project_name - - @project_name += EXTENSION unless File.extname(@project_name) == EXTENSION - end - end - end -end - require 'fileutils' describe Xcodeproj::Command::Create do