Skip to content

Loading…

Add more test coverage for Command #1684

Merged
merged 1 commit into from

2 participants

@carsonmcdonald

This covers Command#run both when --version is given and when it is not.

@alloy
CocoaPods member

Any ideas on the failure? Did you locally update the spec repo fixture?

@carsonmcdonald

@alloy The issue is that the spec_helper version of UI is creating warnings as a string and I forced it to an array in one of these tests. Depending on the order things ran in it made those other tests fail. The real UI has warnings as an array. In the test I added there is a call to print_warnings that won't work when warnings is a string. I initialized warnings as an array in this new test and I didn't realize that this caused the other tests to fail because they expect a single string and not an array of warning strings.

I think this can be solved in a number of ways. One way is to remove making warnings an array in the new test and add a print_warnings in the spec version of UI that does nothing. I think this is the quickest fix and technically print_warnings should probably not do anything while the test is running. Another fix would be to make warnings an array and force it to reset on every call then change the tests that look at it to work with the array output.

@carsonmcdonald

@alloy I went ahead and made the change to make print_warnings do nothing. I'm fine going the other route as well but it is a larger change and probably needs to be done outside of this PR.

@alloy
CocoaPods member

Sure, if that output is currently not being used in tests then this is fine.

@alloy alloy merged commit 4412dac into CocoaPods:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2013
  1. @carsonmcdonald
Showing with 23 additions and 2 deletions.
  1. +2 −2 lib/cocoapods/command.rb
  2. +18 −0 spec/functional/command_spec.rb
  3. +3 −0 spec/spec_helper/user_interface.rb
View
4 lib/cocoapods/command.rb
@@ -45,8 +45,8 @@ def self.parse(argv)
def self.run(argv)
argv = CLAide::ARGV.new(argv)
if argv.flag?('version')
- puts VERSION
- exit!(0)
+ UI.puts VERSION
+ exit 0
end
super(argv)
UI.print_warnings
View
18 spec/functional/command_spec.rb
@@ -0,0 +1,18 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+module Pod
+ describe Command do
+ extend SpecHelper::Command
+
+ it "displays the current version number with the --version flag" do
+ lambda { Pod::Command.run(['--version']) }.should.raise SystemExit
+ UI.output.should.include VERSION
+ end
+
+ it "reports the location of the AFNetworking spec" do
+ lambda { Pod::Command.run(['spec', 'which', 'AFNetworking']) }.should.not.raise
+ UI.output.should.include 'spec/fixtures/spec-repos/master/AFNetworking'
+ end
+
+ end
+end
View
3 spec/spec_helper/user_interface.rb
@@ -25,6 +25,9 @@ def warn(message = '', actions = [])
def print(message)
@output << message
end
+
+ def print_warnings
+ end
end
end
end
Something went wrong with that request. Please try again.