Browse files

Add tests for the spec edit command

  • Loading branch information...
1 parent cb539e2 commit c34c84a917a1537121d404c7ef30451566553118 @carsonmcdonald carsonmcdonald committed Jan 12, 2014
Showing with 53 additions and 0 deletions.
  1. +35 −0 spec/functional/command/spec_spec.rb
  2. +18 −0 spec/spec_helper.rb
View
35 spec/functional/command/spec_spec.rb
@@ -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
#-------------------------------------------------------------------------#
View
18 spec/spec_helper.rb
@@ -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'

0 comments on commit c34c84a

Please sign in to comment.