Skip to content

Commit

Permalink
Add tests for the spec edit command
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonmcdonald committed Jan 12, 2014
1 parent cb539e2 commit c34c84a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/functional/command/spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,43 @@ def it_should_check_for_ambiguity(command)
#-------------------------------------------------------------------------#

describe Command::Spec::Edit do
before do
@path_saved = ENV['PATH']
end

after do
ENV['PATH'] = @path_saved
end

it_should_check_for_existence("edit")
it_should_check_for_ambiguity("edit")

it "would execute the editor specified in ENV with the given podspec" do
ENV['EDITOR'] = 'podspeceditor'
lambda { command('spec', 'edit', 'AFNetworking').run }.should.raise SystemExit
UI.output.should.include '/bin/sh -i -c podspeceditor "$@" --'
UI.output.should.include 'fixtures/spec-repos/master/AFNetworking'
end

it "will raise if no editor is found" do
ENV['PATH'] = ''
ENV['EDITOR'] = nil
lambda { command('spec', 'edit', 'AFNetworking').run }.should.raise Informative
end

it "would execute an editor with the first podspec from all podspecs" do
ENV['EDITOR'] = 'podspeceditor'
UI.next_input = "1\n"
lambda { command('spec', 'edit', '--show-all', 'AFNetworking').run }.should.raise SystemExit
UI.output.should.include '/bin/sh -i -c podspeceditor "$@" --'
UI.output.should.include 'fixtures/spec-repos/master/AFNetworking/1.2.0/AFNetworking.podspec'
end

it "complains if it can't find a spec file for the given spec" do
File.stubs(:exists?).returns(false)
lambda { command('spec', 'edit', 'AFNetworking').run }.should.raise Informative
File.unstub(:exists?)
end
end

#-------------------------------------------------------------------------#
Expand Down
18 changes: 18 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ def source
end
end

# README!
#
# Adds {Command::Spec::Edit#exec} to fake the {Kernel#exec} call that would
# normally be made during an edit.
#
module Pod
class Command
class Spec
class Edit
def exec(cmd, *args)
UI.puts "#{cmd} #{args.join(' ')}"
raise SystemExit
end
end
end
end
end

#-----------------------------------------------------------------------------#

ENV['SKIP_SETUP'] = 'true'
Expand Down

0 comments on commit c34c84a

Please sign in to comment.