Commit 22518894 authored by Florian R. Hanke's avatar Florian R. Hanke

Merge pull request #1893 from CocoaPods/web_search_regex

Web search regex
parents 9c478fbe 9471d58c
......@@ -36,10 +36,14 @@ module Pod
super
help! "A search query is required." unless @query
unless @web
begin
/#{@query.join(' ').strip}/
rescue RegexpError
help! "A valid regular expression is required."
end
end
end
def run
if @web
......@@ -54,11 +58,11 @@ module Pod
def web_search
query_parameter = [
('on%3Aosx' if @supported_on_osx),
('on%3Aios' if @supported_on_ios),
('on:osx' if @supported_on_osx),
('on:ios' if @supported_on_ios),
@query
].compact.flatten.join('%20')
url = "http://cocoapods.org/?q=#{query_parameter}"
].compact.flatten.join(' ')
url = "http://cocoapods.org/?q=#{CGI.escape(query_parameter).gsub("+", "%20")}"
UI.puts("Opening #{url}")
open!(url)
end
......
......@@ -50,7 +50,7 @@ module Pod
output.should.include? 'BananaLib'
end
it "shows a friendly message when searching with invalid regex" do
it "shows a friendly message when locally searching with invalid regex" do
lambda { run_command('search', '+') }.should.raise CLAide::Help
end
......@@ -58,6 +58,16 @@ module Pod
extend SpecHelper::TemporaryRepos
it "searches with invalid regex" do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=NSAttributedString%2BCCLFormat')
run_command('search', '--web', 'NSAttributedString+CCLFormat')
end
it "should url encode search queries" do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=NSAttributedString%2BCCLFormat')
run_command('search', '--web', 'NSAttributedString+CCLFormat')
end
it "searches the web via the open! command" do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=bananalib')
run_command('search', '--web', 'bananalib')
......
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