From 57afe1ce2cf2dcac56d5860e0cdb8d0d2af4f83b Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Fri, 8 May 2015 23:36:38 +0900 Subject: [PATCH] Add test. --- Rakefile | 8 +++++ test/test_core.rb | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Rakefile create mode 100644 test/test_core.rb diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..debc11c --- /dev/null +++ b/Rakefile @@ -0,0 +1,8 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs << 'test' +end + +desc "Run tests" +task :default => :test diff --git a/test/test_core.rb b/test/test_core.rb new file mode 100644 index 0000000..5390f73 --- /dev/null +++ b/test/test_core.rb @@ -0,0 +1,77 @@ +require 'test/unit' + +require_relative "../lib/cocoaseeds" + +class CoreTest < Test::Unit::TestCase + + def setup + pwd = File.expand_path(File.dirname(__FILE__)) + + @project_dirname = File.join(pwd, "TestProj") + @seeds_dirname = File.join(@project_dirname, "Seeds") + + # clean + FileUtils.rm_rf(@project_dirname) + + # create a new project + @project_filename = File.join(@project_dirname, "TestProj.xcodeproj") + project = Xcodeproj::Project.new(@project_filename) + project.new_target(:application, "TestProj", :ios) + project.save + + # cocoaseeds + @seed = Seeds::Core.new(@project_dirname) + end + + def teardown + FileUtils.rm_rf(@project_dirname) + end + + def project + Xcodeproj::Project.open(@project_filename) + end + + def seedfile(content) + path = File.join(@project_dirname, "Seedfile") + content = content ? content.strip.sub(/^\s+/, '') : '' + File.write(path, content) + end + + def test_install + seedfile %{ + github "devxoul/JLToast", "1.2.2", :files => "JLToast/*.{h,swift}" + } + @seed.install + + assert\ + File.exists?(File.join(@seeds_dirname, "JLToast")), + "Directory Seeds/JLToast not exists." + + assert_not_nil\ + self.project["Seeds"]["JLToast"], + "Group 'Seeds/JLToast' not exists in the project." + + self.project["Seeds"]["JLToast"].files.each do |file| + assert_match /.*\.(h|swift)/, file.name + end + end + + def test_remove + seedfile %{ + github "devxoul/JLToast", "1.2.2", :files => "JLToast/*.{h,swift}" + } + @seed.install + + seedfile nil + @seed.install + + assert\ + !File.exists?(File.join(@seeds_dirname, "JLToast")), + "Directory Seeds/JLToast exists." + + assert_nil\ + self.project["Seeds"]["JLToast"], + "Group 'Seeds/JLToast' exists in the project." + end + +end