Commit 064958d4 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Spec] Fix ErrorReport spec

parent 3762f5a1
...@@ -7,9 +7,6 @@ module Pod ...@@ -7,9 +7,6 @@ module Pod
module UserInterface module UserInterface
module ErrorReport module ErrorReport
class << self class << self
def pathless_exception_message(message)
message.gsub(/- \(.*\):/, '-')
end
def report(exception) def report(exception)
return <<-EOS return <<-EOS
...@@ -49,7 +46,7 @@ Repositories : #{repo_information.join("\n ")} ...@@ -49,7 +46,7 @@ Repositories : #{repo_information.join("\n ")}
#{'[!] Oh no, an error occurred.'.red} #{'[!] Oh no, an error occurred.'.red}
#{error_from_podfile(exception)} #{error_from_podfile(exception)}
#{'Search for existing github issues similar to yours:'.yellow} #{'Search for existing github issues similar to yours:'.yellow}
#{"https://github.com/CocoaPods/CocoaPods/search?q=#{CGI.escape(pathless_exception_message(exception.message))}&type=Issues"} #{issues_url(exception)}
#{'If none exists, create a ticket, with the template displayed above, on:'.yellow} #{'If none exists, create a ticket, with the template displayed above, on:'.yellow}
https://github.com/CocoaPods/CocoaPods/issues/new https://github.com/CocoaPods/CocoaPods/issues/new
...@@ -61,6 +58,10 @@ EOS ...@@ -61,6 +58,10 @@ EOS
private private
def pathless_exception_message(message)
message.gsub(/- \(.*\):/, '-')
end
def markdown_podfile def markdown_podfile
return '' unless Config.instance.podfile_path && Config.instance.podfile_path.exist? return '' unless Config.instance.podfile_path && Config.instance.podfile_path.exist?
<<-EOS <<-EOS
...@@ -79,6 +80,16 @@ EOS ...@@ -79,6 +80,16 @@ EOS
end end
end end
def remove_color(string)
string.gsub(/\e\[(\d+)m/, '')
end
def issues_url(exception)
message = remove_color(pathless_exception_message(exception.message))
'https://github.com/CocoaPods/CocoaPods/search?q=' \
"#{CGI.escape(message)}&type=Issues"
end
def host_information def host_information
product, version, build =`sw_vers`.strip.split("\n").map { |line| line.split(":").last.strip } product, version, build =`sw_vers`.strip.split("\n").map { |line| line.split(":").last.strip }
"#{product} #{version} (#{build})" "#{product} #{version} (#{build})"
......
...@@ -9,7 +9,7 @@ module Pod ...@@ -9,7 +9,7 @@ module Pod
describe 'In general' do describe 'In general' do
before do before do
@exception = Informative.exception('at - (~/code.rb):') @exception = Informative.exception('at - (~/code.rb):')
@exception.stubs(:backtrace).returns(%w{Line 1 Line 2}) @exception.stubs(:backtrace).returns(['Line 1', 'Line 2'])
@report = UserInterface::ErrorReport @report = UserInterface::ErrorReport
end end
...@@ -59,7 +59,7 @@ Line 2 ...@@ -59,7 +59,7 @@ Line 2
[!] Oh no, an error occurred. [!] Oh no, an error occurred.
Search for existing github issues similar to yours: Search for existing github issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=%1B%5B31m%5B%21%5D+at+-%1B%5B0m&type=Issues https://github.com/CocoaPods/CocoaPods/search?q=%5B%21%5D+at+-&type=Issues
If none exists, create a ticket, with the template displayed above, on: If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new https://github.com/CocoaPods/CocoaPods/issues/new
...@@ -79,11 +79,12 @@ EOS ...@@ -79,11 +79,12 @@ EOS
@report.stubs(:xcode_information).returns(':xcode_information') @report.stubs(:xcode_information).returns(':xcode_information')
@report.stubs(:repo_information).returns(['repo_1', 'repo_2']) @report.stubs(:repo_information).returns(['repo_1', 'repo_2'])
report = remove_color(@report.report(@exception)) report = remove_color(@report.report(@exception))
puts report
report.should == expected report.should == expected
end end
it 'strips the local path from the exception message' do it 'strips the local path from the exception message' do
message = @report.pathless_exception_message(@exception.message) message = @report.send(:pathless_exception_message, @exception.message)
message = remove_color(message) message = remove_color(message)
message.should == '[!] at -' message.should == '[!] at -'
end end
......
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