Commit 0c5fb77d authored by Fabio Pelosin's avatar Fabio Pelosin

Enhanced specs for Pod::Command and subclasses

parent 029d19eb
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Repo" do
extend SpecHelper::Command
extend SpecHelper::Git
extend SpecHelper::TemporaryDirectory
it "runs with correct parameters" do
lambda { run_command('repo', 'add', 'NAME', 'URL') }.should.not.raise
lambda { run_command('repo', 'update') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('repo', 'add') }.should.raise Pod::Informative
lambda { run_command('repo', 'add', 'NAME') }.should.raise Pod::Informative
end
it "adds a spec-repo" do
add_repo('private', fixture('spec-repos/master'))
git_config('private', 'remote.origin.url').should == fixture('spec-repos/master').to_s
end
it "updates a spec-repo" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
git('repo1', 'checkout master') # checkout master, because the fixture is a submodule
repo2 = add_repo('repo2', repo1.dir)
make_change(repo1, 'repo1')
run_command('repo', 'update', 'repo2')
(repo2.dir + 'README').read.should.include 'Added!'
end
it "updates all the spec-repos" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
git('repo1', 'checkout master') # checkout master, because the fixture is a submodule
repo2 = add_repo('repo2', repo1.dir)
repo3 = add_repo('repo3', repo1.dir)
make_change(repo1, 'repo1')
run_command('repo', 'update')
(repo2.dir + 'README').read.should.include 'Added!'
(repo3.dir + 'README').read.should.include 'Added!'
end
before do
add_repo('repo1', fixture('spec-repos/master'))
versions_file.should.not.exist?
end
require 'yaml'
def versions_file
tmp_repos_path + "repo1/CocoaPods-version.yml"
end
it "it doesn't requires CocoaPods-version.yml" do
lambda { run_command('repo', 'update') }.should.not.raise
end
it "runs with a compatible repo" do
yaml = YAML.dump({:min => "0.0.1"})
File.open(versions_file, 'w') {|f| f.write(yaml) }
lambda { run_command('repo', 'update') }.should.not.raise
end
it "raises if a repo is not compatible" do
yaml = YAML.dump({:min => "999.0.0"})
File.open(versions_file, 'w') {|f| f.write(yaml) }
lambda { run_command('repo', 'update') }.should.raise Pod::Informative
end
it "informs about a higher known CocoaPods version" do
yaml = YAML.dump({:last => "999.0.0"})
File.open(versions_file, 'w') {|f| f.write(yaml) }
run_command('repo', 'update').should.include "Cocoapods 999.0.0 is available"
end
end
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Search" do
extend SpecHelper::Command
extend SpecHelper::Git
before do
......@@ -11,27 +12,43 @@ describe "Pod::Command::Search" do
config.repos_dir = tmp_repos_path
end
def command(arguments = argv)
command = Pod::Command::Search.new(arguments)
end
it "runs with correct parameters" do
lambda { command(argv('table')).run }.should.not.raise
lambda { command(argv('table','--full')).run }.should.not.raise
lambda { run_command('search', 'table') }.should.not.raise
lambda { run_command('search', 'table', '--full') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { command(argv('too','many')).run }.should.raise Pod::Command::Help
lambda { command(argv('too','--wrong')).run }.should.raise Pod::Command::Help
lambda { command(argv('--missing_query')).run }.should.raise Pod::Command::Help
lambda { run_command('search', 'too', 'many') }.should.raise Pod::Command::Help
lambda { run_command('search', 'too', '--wrong') }.should.raise Pod::Command::Help
lambda { run_command('search', '--wrong') }.should.raise Pod::Command::Help
end
it "presents the search results" do
search = command(argv('table'))
search.run
output = search.output
output = run_command('search', 'table')
output.should.include 'EGOTableViewPullRefresh'
end
it "searches for a pod with name matching the given query ignoring case" do
[
[' s ', %w{ ASIHTTPRequest ASIWebPageRequest JSONKit SSZipArchive }],
['json', %w{ JSONKit SBJson }],
].each do |query, results|
output = run_command('search', query)
results.each { |pod| output.should.include? pod }
end
end
it "searches for a pod with name, summary, or description matching the given query ignoring case" do
[
['dROP', %w{ Reachability }],
['is', %w{ ASIHTTPRequest SSZipArchive }],
['luke redpath', %w{ Kiwi libPusher LRMocky LRResty LRTableModel}],
].each do |query, results|
output = run_command('search', '--full', query)
results.each { |pod| output.should.include? pod }
end
end
end
......
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Setup" do
extend SpecHelper::Command
extend SpecHelper::Git
extend SpecHelper::TemporaryDirectory
it "runs with correct parameters" do
lambda { run_command('setup') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('setup', 'wrong') }.should.raise Pod::Command::Help
lambda { run_command('setup', '--wrong') }.should.raise Pod::Command::Help
end
it "returns the read only URL of the `master' spec-repo" do
cmd = Pod::Command::Setup.new(argv)
cmd.url.should == 'git://github.com/CocoaPods/Specs.git'
end
it "returns the push URL of the `master' spec-repo" do
config.silent = true
cmd = Pod::Command::Setup.new(argv('--push'))
cmd.url.should == 'git@github.com:CocoaPods/Specs.git'
end
class Pod::Command::Setup
def read_only_url; SpecHelper.fixture('spec-repos/master'); end
end
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
output = run_command('setup')
git_config('master', 'remote.origin.url').should == fixture('spec-repos/master').to_s
output.should.include "Setup completed"
output.should.not.include "push"
end
it "preserves push access for the `master' repo" do
output = run_command('setup')
output.should.not.include "push"
git('master', 'remote set-url origin git@github.com:CocoaPods/Specs.git')
command('setup').url.should == 'git@github.com:CocoaPods/Specs.git'
end
it "can run if needed" do
output = run_command('setup')
output.should.include "Setup completed"
command = command('setup')
command.run_if_needed
command.output.should == nil
end
end
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Spec" do
extend SpecHelper::Command
extend SpecHelper::Github
extend SpecHelper::TemporaryDirectory
it "runs with correct parameters" do
lambda{ run_command('spec', 'create', 'Bananas') }.should.not.raise
expect_github_repo_request
expect_github_user_request
expect_github_tags_request
lambda{ run_command('spec', 'create', 'https://github.com/lukeredpath/libPusher.git') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('spec', '--create') }.should.raise Pod::Command::Help
lambda { run_command('spec', 'createa') }.should.raise Pod::Command::Help
lambda { run_command('spec', 'create') }.should.raise Pod::Command::Help
end
it "creates a new podspec stub file" do
run_command('spec', 'create', 'Bananas')
path = temporary_directory + 'Bananas.podspec'
spec = Pod::Specification.from_file(path)
spec.name.should == 'Bananas'
spec.license.should == { :type => "MIT", :file => "LICENSE" }
spec.version.should == Pod::Version.new('0.0.1')
spec.summary.should == 'A short description of Bananas.'
spec.homepage.should == 'http://EXAMPLE/Bananas'
spec.authors.should == { `git config --get user.name`.strip => `git config --get user.email`.strip}
spec.source.should == { :git => 'http://EXAMPLE/Bananas.git', :tag => '0.0.1' }
spec.description.should == 'An optional longer description of Bananas.'
spec.source_files[:ios].should == ['Classes', 'Classes/**/*.{h,m}']
end
it "correctly creates a podspec from github" do
expect_github_repo_request
expect_github_user_request
expect_github_tags_request
run_command('spec', 'create', 'https://github.com/lukeredpath/libPusher.git')
path = temporary_directory + 'libPusher.podspec'
spec = Pod::Specification.from_file(path)
spec.name.should == 'libPusher'
spec.license.should == { :type => "MIT", :file => "LICENSE" }
spec.version.should == Pod::Version.new('1.3')
spec.summary.should == 'An Objective-C interface to Pusher (pusherapp.com)'
spec.homepage.should == 'https://github.com/lukeredpath/libPusher'
spec.authors.should == {"Luke Redpath"=>"luke@lukeredpath.co.uk"}
spec.source.should == { :git => 'https://github.com/lukeredpath/libPusher.git', :tag => 'v1.3' }
end
it "correctly suggests the head commit if a suitable tag is not available on github" do
expect_github_repo_request
expect_github_user_request
expect_github_tags_request([{"name" => "experiment"}])
expect_github_branches_request
run_command('spec', 'create', 'https://github.com/lukeredpath/libPusher.git')
path = temporary_directory + 'libPusher.podspec'
spec = Pod::Specification.from_file(path)
spec.version.should == Pod::Version.new('0.0.1')
spec.source.should == { :git => 'https://github.com/lukeredpath/libPusher.git', :commit => '5f482b0693ac2ac1ad85d1aabc27ec7547cc0bc7' }
end
it "provides a markdown template if a github repo doesn't have semantic version tags" do
expect_github_repo_request
expect_github_user_request
expect_github_tags_request([{"name" => "experiment"}])
expect_github_branches_request
output = run_command('spec', 'create', 'https://github.com/lukeredpath/libPusher.git')
output.should.include 'MARKDOWN TEMPLATE'
output.should.include 'Please add semantic version tags'
end
end
require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Command" do
extend SpecHelper::Git
extend SpecHelper::TemporaryDirectory
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
command = Pod::Command.parse('setup', '--silent')
def command.url; SpecHelper.fixture('spec-repos/master'); end
command.run
git_config('master', 'remote.origin.url').should == fixture('spec-repos/master').to_s
end
it "preserve push access for the `master' repo" do
command = Pod::Command.parse('setup', '--silent')
def command.url; SpecHelper.fixture('spec-repos/master'); end
command.run
command2 = Pod::Command.parse('setup', '--silent')
command2.url.should == 'git://github.com/CocoaPods/Specs.git'
git('master', 'remote set-url origin git@github.com:CocoaPods/Specs.git')
command2.url.should == 'git@github.com:CocoaPods/Specs.git'
end
it "adds a spec-repo" do
add_repo('private', fixture('spec-repos/master'))
git_config('private', 'remote.origin.url').should == fixture('spec-repos/master').to_s
end
it "updates a spec-repo" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
git('repo1', 'checkout master') # checkout master, because the fixture is a submodule
repo2 = add_repo('repo2', repo1.dir)
make_change(repo1, 'repo1')
command('repo', 'update', 'repo2')
(repo2.dir + 'README').read.should.include 'Added!'
end
it "updates all the spec-repos" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
git('repo1', 'checkout master') # checkout master, because the fixture is a submodule
repo2 = add_repo('repo2', repo1.dir)
repo3 = add_repo('repo3', repo1.dir)
make_change(repo1, 'repo1')
command('repo', 'update')
(repo2.dir + 'README').read.should.include 'Added!'
(repo3.dir + 'README').read.should.include 'Added!'
end
it "creates a new podspec stub file" do
Dir.chdir(temporary_directory) do
command('spec', 'create', 'Bananas')
end
path = temporary_directory + 'Bananas.podspec'
spec = Pod::Specification.from_file(path)
spec.name.should == 'Bananas'
spec.license.should == { :type => "MIT", :file => "LICENSE" }
spec.version.should == Pod::Version.new('0.0.1')
spec.summary.should == 'A short description of Bananas.'
spec.homepage.should == 'http://EXAMPLE/Bananas'
spec.authors.should == { `git config --get user.name`.strip => `git config --get user.email`.strip}
spec.source.should == { :git => 'http://EXAMPLE/Bananas.git', :tag => '0.0.1' }
spec.description.should == 'An optional longer description of Bananas.'
spec.source_files[:ios].should == ['Classes', 'Classes/**/*.{h,m}']
end
before do
config.repos_dir = fixture('spec-repos')
end
after do
config.repos_dir = tmp_repos_path
end
it "searches for a pod with name matching the given query ignoring case" do
[
[' s ', %w{ ASIHTTPRequest ASIWebPageRequest JSONKit SSZipArchive }],
['json', %w{ JSONKit SBJson }],
].each do |query, results|
command = Pod::Command.parse('search', '--silent', query)
def command.puts(msg = '')
(@printed ||= '') << "#{msg}\n"
end
command.run
printed = command.instance_variable_get(:@printed)
results.each { |pod| printed.should.include? pod }
end
end
it "searches for a pod with name, summary, or description matching the given query ignoring case" do
[
['dROP', %w{ Reachability }],
['is', %w{ ASIHTTPRequest SSZipArchive }],
].each do |query, results|
command = Pod::Command.parse('search', '--silent', '--full', query)
def command.puts(msg = '')
(@printed ||= '') << "#{msg}\n"
end
command.run
printed = command.instance_variable_get(:@printed)
results.each { |pod| printed.should.include? pod }
end
end
end
# describe "Pod::Command" do
# extend SpecHelper::Command
# extend SpecHelper::Git
# extend SpecHelper::TemporaryDirectory
#
# TODO:
# it "raises help informative if an unknown parameter is passed"
# it "performs setup if needed"
# end
......@@ -13,8 +13,10 @@ require 'cocoapods'
$:.unshift((ROOT + 'spec').to_s)
require 'spec_helper/color_output'
require 'spec_helper/command'
require 'spec_helper/fixture'
require 'spec_helper/git'
require 'spec_helper/github'
require 'spec_helper/temporary_directory'
module Bacon
......@@ -83,10 +85,5 @@ VCR.configure do |c|
c.allow_http_connections_when_no_cassette = true
end
class Pod::Command
attr_accessor :output
def puts(msg = '') (@output ||= '') << "#{msg}\n" end
end
Pod::Specification::Statistics.instance.cache_file = nil
require 'spec_helper/temporary_directory'
class Pod::Command
attr_accessor :output
def puts(msg = '') (@output ||= '') << "#{msg}\n" end
end
module SpecHelper
module Command
def command(*argv)
Pod::Command.parse(*argv)
end
def run_command(*args)
Dir.chdir(SpecHelper.temporary_directory) do
command = command(*args)
command.run
command.output
end
end
end
end
......@@ -2,7 +2,7 @@ module SpecHelper
def self.fixture(name)
Fixture.fixture(name)
end
def self.create_sample_app_copy_from_fixture(fixture_name)
fixture_copy_path = temporary_directory + fixture_name
FileUtils.cp_r(fixture(fixture_name), temporary_directory)
......
......@@ -31,17 +31,12 @@ module SpecHelper
git repo, "config --get #{attr}"
end
def command(*argv)
argv << '--silent'
command = Pod::Command.parse(*argv)
def add_repo(name, from)
command = command('repo', 'add', name, from)
command.run
command
end
def add_repo(name, from)
command('repo', 'add', name, from)
end
def make_change(repo, name)
(repo.dir + 'README').open('w') { |f| f << 'Added!' }
git(name, 'add README')
......
module SpecHelper
module Github
def expect_github_repo_request(data = nil)
data ||= {
"clone_url" => "https://github.com/lukeredpath/libPusher.git",
"created_at" => "2010-03-22T17:06:16Z",
"description" => "An Objective-C interface to Pusher (pusherapp.com)",
"fork" => false,
"forks" => 22,
"git_url" => "git://github.com/lukeredpath/libPusher.git",
"has_downloads" => true,
"has_issues" => true,
"has_wiki" => true,
"homepage" => "",
"html_url" => "https://github.com/lukeredpath/libPusher",
"id" => 574304,
"language" => "C",
"mirror_url" => nil,
"name" => "libPusher",
"open_issues" => 2,
"owner" => {
"avatar_url" => "https://secure.gravatar.com/avatar/bdd4d23d1a822b2d68b53e7c51d69a39?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"gravatar_id" => "bdd4d23d1a822b2d68b53e7c51d69a39",
"id" => 613,
"login" => "lukeredpath",
"url" => "https://api.github.com/users/lukeredpath"
},
"private" => false,
"pushed_at" => "2012-04-10T13:16:49Z",
"size" => 3654,
"ssh_url" => "git@github.com:lukeredpath/libPusher.git",
"svn_url" => "https://github.com/lukeredpath/libPusher",
"updated_at" => "2012-04-16T23:01:00Z",
"url" => "https://api.github.com/repos/lukeredpath/libPusher",
"watchers" => 143
}
Octokit.expects(:repo).with('lukeredpath/libPusher').returns(data)
end
def expect_github_tags_request(data = nil)
data ||= [
{
"commit" => {
"sha" => "ea47899b65db8e9fd77b3a236f602771f15ca28f",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/ea47899b65db8e9fd77b3a236f602771f15ca28f"
},
"name" => "v1.2",
"tarball_url" => "https://github.com/lukeredpath/libPusher/tarball/v1.2",
"zipball_url" => "https://github.com/lukeredpath/libPusher/zipball/v1.2"
},
{
"commit" => {
"sha" => "788468bc173e1bb57646a3ff8ace551df10a4249",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/788468bc173e1bb57646a3ff8ace551df10a4249"
},
"name" => "v1.0.1",
"tarball_url" => "https://github.com/lukeredpath/libPusher/tarball/v1.0.1",
"zipball_url" => "https://github.com/lukeredpath/libPusher/zipball/v1.0.1"
},
{
"commit" => {
"sha" => "d4d51f86dc460c389b9d19c9453541f7daf7076b",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/d4d51f86dc460c389b9d19c9453541f7daf7076b"
},
"name" => "v1.3",
"tarball_url" => "https://github.com/lukeredpath/libPusher/tarball/v1.3",
"zipball_url" => "https://github.com/lukeredpath/libPusher/zipball/v1.3"
},
{
"commit" => {
"sha" => "c4ed3712ad2bee5c9e754339f1860f15daf788f4",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/c4ed3712ad2bee5c9e754339f1860f15daf788f4"
},
"name" => "v1.0",
"tarball_url" => "https://github.com/lukeredpath/libPusher/tarball/v1.0",
"zipball_url" => "https://github.com/lukeredpath/libPusher/zipball/v1.0"
},
{
"commit" => {
"sha" => "77523befd5509f91b8cbe03f45d30e6ce8ab96f4",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/77523befd5509f91b8cbe03f45d30e6ce8ab96f4"
},
"name" => "v1.1",
"tarball_url" => "https://github.com/lukeredpath/libPusher/tarball/v1.1",
"zipball_url" => "https://github.com/lukeredpath/libPusher/zipball/v1.1"
}
]
Octokit.expects(:tags).with(:username => 'lukeredpath', :repo => 'libPusher').returns(data)
end
def expect_github_branches_request(data = nil)
data ||= [
{
"commit" => {
"sha" => "d7aac34e846e2fe9b9da54978abfada8f9aa69a8",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/d7aac34e846e2fe9b9da54978abfada8f9aa69a8"
},
"name" => "use-socketrocket-backend"
},
{
"commit" => {
"sha" => "daa4ba9398af4b532bfbca610065057e709cc877",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/daa4ba9398af4b532bfbca610065057e709cc877"
},
"name" => "gh-pages"
},
{
"commit" => {
"sha" => "5f482b0693ac2ac1ad85d1aabc27ec7547cc0bc7",
"url" => "https://api.github.com/repos/lukeredpath/libPusher/commits/5f482b0693ac2ac1ad85d1aabc27ec7547cc0bc7"
},
"name" => "master"
}
]
Octokit.expects(:branches).with(:username => 'lukeredpath', :repo => 'libPusher').returns(data)
end
def expect_github_user_request(data = nil)
data ||= {
"avatar_url" => "https://secure.gravatar.com/avatar/bdd4d23d1a822b2d68b53e7c51d69a39?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png",
"bio" => "I\342\200\231m a Ruby on Rails and iPhone developer based in London, UK. I\342\200\231ve been writing web apps for almost ten years and in late 2008, I released my first iPhone application.\r\n\r\nSince early 2009, I have worked on a freelance/contract basis, having previously worked at Reevoo as part of one of the best Rails development teams in the country.\r\n\r\nI\342\200\231m also a big fan of open-source software which I both use and contribute to whenever possible. I have contributed to many open-source projects over the years, including Rails, RSpec and more recently, Gemcutter, as well as starting many of my own, including Clickatell, a library for interfacing with the Clickatell SMS gateway and SimpleConfig, a declarative application configuration Rails plugin which was developed whilst working at Reevoo.\r\n\r\nI was the technical reviewer for the SitePoint book \342\200\234Build Your Own Ruby on Rails Applications\342\200\235 and also contributed a recipe to \342\200\234Rails Recipes\342\200\235 by Chad Fowler.",
"blog" => "http://lukeredpath.co.uk",
"company" => "LJR Software Limited",
"created_at" => "2008-02-22T14:36:59Z",
"email" => "luke@lukeredpath.co.uk",
"followers" => 195,
"following" => 10,
"gravatar_id" => "bdd4d23d1a822b2d68b53e7c51d69a39",
"hireable" => true,
"html_url" => "https://github.com/lukeredpath",
"id" => 613,
"location" => "London, UK",
"login" => "lukeredpath",
"name" => "Luke Redpath",
"public_gists" => 122,
"public_repos" => 68,
"type" => "User",
"url" => "https://api.github.com/users/lukeredpath"
}
Octokit.expects(:user).with('lukeredpath').returns(data)
end
end
end
......@@ -2,29 +2,12 @@ require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Command" do
it "returns the proper command class" do
config.silent.should == true
Pod::Command.parse('setup').should.be.instance_of Pod::Command::Setup
#Pod::Command.parse('spec').should.be.instance_of Pod::Command::Spec
Pod::Command.parse('spec', 'create', 'name').should.be.instance_of Pod::Command::Spec
Pod::Command.parse('repo', 'update').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(argv('something')) }.should.raise Pod::Command::Help
end
it "returns the read only URL of the `master' spec-repo" do
command = Pod::Command::Setup.new(argv)
command.url.should == 'git://github.com/CocoaPods/Specs.git'
end
it "returns the push URL of the `master' spec-repo" do
config.silent = true
command = Pod::Command::Setup.new(argv('--push'))
command.url.should == 'git@github.com:CocoaPods/Specs.git'
end
end
describe "Pod::Command::Repo" do
it "complains about unknown arguments" do
......
......@@ -2,6 +2,7 @@ require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Source" do
extend SpecHelper::Git
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
before do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment