Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement the setup command.

  • Loading branch information...
commit 7ce508b5f323debbafcef4a486fb4c75948ef037 1 parent c9e64e3
@alloy alloy authored
View
1  .gitignore
@@ -1,3 +1,4 @@
*.swp
*.swo
.DS_Store
+tmp
View
9 lib/cocoa_pods/command.rb
@@ -1,5 +1,5 @@
module Pod
- module Command
+ class Command
autoload :Help, 'cocoa_pods/command/help'
autoload :Setup, 'cocoa_pods/command/setup'
autoload :Spec, 'cocoa_pods/command/spec'
@@ -15,5 +15,12 @@ def self.parse(*argv)
end
command.new(*argv)
end
+
+ def initialize(*argv)
+ raise "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
+ end
+
+ def run
+ end
end
end
View
4 lib/cocoa_pods/command/help.rb
@@ -1,6 +1,6 @@
module Pod
- module Command
- class Help
+ class Command
+ class Help < Command
end
end
end
View
4 lib/cocoa_pods/command/repo.rb
@@ -1,6 +1,6 @@
module Pod
- module Command
- class Repo
+ class Command
+ class Repo < Command
end
end
end
View
26 lib/cocoa_pods/command/setup.rb
@@ -1,6 +1,28 @@
+require 'fileutils'
+require 'executioner'
+
module Pod
- module Command
- class Setup
+ class Command
+ class Setup < Command
+ include Executioner
+ executable :git
+
+ def repos_dir
+ File.expand_path('~/.cocoa-pods')
+ end
+
+ def master_repo_dir
+ File.join(repos_dir, 'master')
+ end
+
+ def master_repo_url
+ 'git://github.com/alloy/cocoa-pod-specs.git'
+ end
+
+ def run
+ FileUtils.mkdir_p(repos_dir)
+ Dir.chdir(repos_dir) { git("clone #{master_repo_url} master") }
+ end
end
end
end
View
4 lib/cocoa_pods/command/spec.rb
@@ -1,6 +1,6 @@
module Pod
- module Command
- class Spec
+ class Command
+ class Spec < Command
end
end
end
1  spec/fixtures/master-spec-repo.git
@@ -0,0 +1 @@
+Subproject commit c807c4a9bff2af0ada17863065eb44bda0275a7d
View
21 spec/functional/command_spec.rb
@@ -0,0 +1,21 @@
+require File.expand_path('../../spec_helper', __FILE__)
+require 'executioner'
+
+describe "Pod::Command" do
+ extend SpecHelper::Fixture
+ extend SpecHelper::Git
+ extend SpecHelper::Log
+ extend SpecHelper::TemporaryDirectory
+
+ it "creates the local spec-repos directory and creates a clone of the `master' repo" do
+ #log!
+
+ command = Pod::Command.parse("setup")
+ def command.repos_dir; SpecHelper.tmp_repos_path; end
+ def command.master_repo_url; SpecHelper.fixture('master-spec-repo.git'); end
+
+ command.run
+ File.should.exist command.master_repo_dir
+ git_config('remote.origin.url').should == command.master_repo_url
+ end
+end
View
13 spec/spec_helper.rb
@@ -1,5 +1,16 @@
require 'rubygems'
require 'mac_bacon'
-$:.unshift File.expand_path('../../lib', __FILE__)
+ROOT = File.expand_path('../../', __FILE__)
+
+$:.unshift File.join(ROOT, 'lib')
require 'cocoa_pods'
+
+$:.unshift File.join(ROOT, 'spec')
+require 'spec_helper/fixture'
+require 'spec_helper/git'
+require 'spec_helper/log'
+require 'spec_helper/temporary_directory'
+
+#TMP_DIR = SpecHelper::TemporaryDirectory.temporary_directory
+#TMP_COCOA_PODS_DIR = File.join(TMP_DIR, 'cocoa-pods')
View
14 spec/spec_helper/fixture.rb
@@ -0,0 +1,14 @@
+module SpecHelper
+ def self.fixture(name)
+ Fixture.fixture(name)
+ end
+
+ module Fixture
+ ROOT = File.join(::ROOT, 'spec', 'fixtures')
+
+ def fixture(name)
+ File.join(ROOT, name)
+ end
+ module_function :fixture
+ end
+end
View
31 spec/spec_helper/git.rb
@@ -0,0 +1,31 @@
+require 'spec_helper/temporary_directory'
+require 'executioner'
+
+module SpecHelper
+ def self.tmp_repos_path
+ Git.tmp_repos_path
+ end
+
+ module Git
+ def tmp_repos_path
+ File.join(SpecHelper.temporary_directory, 'cocoa-pods')
+ end
+ module_function :tmp_repos_path
+
+ def tmp_master_repo_path
+ File.join(tmp_repos_path, 'master')
+ end
+
+ include Executioner
+ executable :git
+
+ alias_method :git_super, :git
+ def git(command)
+ Dir.chdir(tmp_master_repo_path) { git_super(command).strip }
+ end
+
+ def git_config(attr)
+ git "config --get #{attr}"
+ end
+ end
+end
View
16 spec/spec_helper/log.rb
@@ -0,0 +1,16 @@
+module SpecHelper
+ module Log
+ def log!
+ puts
+ logger = Object.new
+ def logger.debug(msg); puts msg; end
+ Executioner.logger = logger
+ end
+
+ def self.extended(context)
+ context.after do
+ Executioner.logger = nil
+ end
+ end
+ end
+end
View
29 spec/spec_helper/temporary_directory.rb
@@ -0,0 +1,29 @@
+require 'fileutils'
+
+module SpecHelper
+ def self.temporary_directory
+ TemporaryDirectory.temporary_directory
+ end
+
+ module TemporaryDirectory
+ def temporary_directory
+ File.join(ROOT, 'tmp')
+ end
+ module_function :temporary_directory
+
+ def setup_temporary_directory
+ FileUtils.mkdir_p(temporary_directory)
+ end
+
+ def teardown_temporary_directory
+ FileUtils.rm_rf(temporary_directory)
+ end
+
+ def self.extended(base)
+ base.before do
+ teardown_temporary_directory
+ setup_temporary_directory
+ end
+ end
+ end
+end
View
22 spec/unit/command_spec.rb
@@ -8,3 +8,25 @@
Pod::Command.parse("repo").should.be.instance_of Pod::Command::Repo
end
end
+
+describe "Pod::Command::Setup" do
+ it "complains about unknown arguments" do
+ lambda { Pod::Command::Setup.new('something') }.should.raise
+ end
+
+ before do
+ @command = Pod::Command::Setup.new
+ end
+
+ it "returns the URL of the `master' spec-repo" do
+ @command.master_repo_url.should == 'git://github.com/alloy/cocoa-pod-specs.git'
+ end
+
+ it "returns the path of the directory where the local spec-repos will be stored" do
+ @command.repos_dir.should == File.expand_path("~/.cocoa-pods")
+ end
+
+ it "returns the path of the directory where the `master' spec-repo will be" do
+ @command.master_repo_dir.should == File.expand_path("~/.cocoa-pods/master")
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.