gem-search 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -17
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -3
- data/Rakefile +2 -2
- data/bin/gem-search +1 -1
- data/gem-search.gemspec +16 -16
- data/lib/gem_search.rb +7 -7
- data/lib/gem_search/command_builder.rb +30 -30
- data/lib/gem_search/commands.rb +5 -5
- data/lib/gem_search/commands/base.rb +10 -10
- data/lib/gem_search/commands/browse.rb +9 -9
- data/lib/gem_search/commands/run.rb +28 -28
- data/lib/gem_search/rendering.rb +30 -30
- data/lib/gem_search/request.rb +15 -15
- data/lib/gem_search/utils/system_util.rb +5 -5
- data/lib/gem_search/version.rb +1 -1
- data/spec/bin/gem_search_spec.rb +12 -12
- data/spec/commands/browse_spec.rb +14 -14
- data/spec/commands/run_spec.rb +64 -64
- data/spec/helpers.rb +1 -1
- data/spec/spec_helper.rb +10 -10
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2384367dcc8179889fed95f58eb247a2452b0dea
|
4
|
+
data.tar.gz: 26460b4b4a183025c684dfcf593a9dbe628c5a02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6aa2cdc66b842fe3c1f34cafce18eaa8035372fafc6e13bc9097c668dccc2781fb004e8109bb512a15ef7d614aef791d1ce6c7219d4b5a5f1d22f25d28e34d5
|
7
|
+
data.tar.gz: 7bc0f2efd92ddf5df728534d4db9a9a4dd073c770ab368739e4efc8ce73ac79e7ab857c87bc45a3b1ccb46687d1e32d53ad0d5115c0daa2f3a0888ee0c646727
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,17 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Style/Documentation:
|
5
|
-
Enabled: false
|
6
|
-
|
7
|
-
Style/ClassAndModuleChildren:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Style/FileName:
|
11
|
-
Exclude: ['bin/gem-search']
|
12
|
-
|
13
|
-
Style/FormatString:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Style/NumericLiterals:
|
17
|
-
Enabled: false
|
1
|
+
inherit_from:
|
2
|
+
- https://raw.githubusercontent.com/rails/rails/master/.rubocop.yml
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/gem-search
CHANGED
data/gem-search.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../lib/gem_search/version", __FILE__)
|
2
2
|
|
3
3
|
def install_message
|
4
|
-
s =
|
4
|
+
s = ""
|
5
5
|
s << "\xf0\x9f\x8d\xba " if or_over_mac_os_lion?
|
6
|
-
s <<
|
6
|
+
s << "Thanks for installing!"
|
7
7
|
end
|
8
8
|
|
9
9
|
def or_over_mac_os_lion?
|
@@ -11,30 +11,30 @@ def or_over_mac_os_lion?
|
|
11
11
|
|
12
12
|
macos_full_version = `/usr/bin/sw_vers -productVersion`.chomp
|
13
13
|
macos_version = macos_full_version[/10\.\d+/]
|
14
|
-
macos_version >=
|
14
|
+
macos_version >= "10.7" # 10.7 is lion
|
15
15
|
end
|
16
16
|
|
17
17
|
Gem::Specification.new do |gem|
|
18
|
-
gem.authors = [
|
19
|
-
gem.email = [
|
20
|
-
gem.homepage =
|
21
|
-
gem.summary =
|
18
|
+
gem.authors = ["rochefort"]
|
19
|
+
gem.email = ["terasawan@gmail.com"]
|
20
|
+
gem.homepage = "https://github.com/rochefort/gem-search"
|
21
|
+
gem.summary = "search gems with using rubygems.org API"
|
22
22
|
gem.description = gem.summary
|
23
23
|
|
24
24
|
gem.files = `git ls-files -z`.split("\x0")
|
25
25
|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
26
26
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
27
|
-
gem.name =
|
28
|
-
gem.require_paths = [
|
27
|
+
gem.name = "gem-search"
|
28
|
+
gem.require_paths = ["lib"]
|
29
29
|
gem.version = GemSearch::VERSION
|
30
30
|
|
31
31
|
gem.post_install_message = install_message
|
32
32
|
|
33
|
-
gem.add_dependency
|
34
|
-
gem.add_dependency
|
33
|
+
gem.add_dependency "slop", "~>4.4.1"
|
34
|
+
gem.add_dependency "mem", "~>0.1.5"
|
35
35
|
|
36
|
-
gem.add_development_dependency
|
37
|
-
gem.add_development_dependency
|
38
|
-
gem.add_development_dependency
|
39
|
-
gem.add_development_dependency
|
36
|
+
gem.add_development_dependency "webmock", "~>2.1.0"
|
37
|
+
gem.add_development_dependency "rake", "~>11.3.0"
|
38
|
+
gem.add_development_dependency "rspec", "~>3.5.0"
|
39
|
+
gem.add_development_dependency "simplecov", "~>0.12.0"
|
40
40
|
end
|
data/lib/gem_search.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module GemSearch
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "mem"
|
3
|
+
require "slop"
|
4
4
|
|
5
|
-
RUBYGEMS_URL =
|
5
|
+
RUBYGEMS_URL = "https://rubygems.org"
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
7
|
+
require "gem_search/command_builder"
|
8
|
+
require "gem_search/commands"
|
9
|
+
require "gem_search/request"
|
10
|
+
require "gem_search/version"
|
11
11
|
end
|
@@ -14,39 +14,39 @@ module GemSearch
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def command_class
|
18
|
+
case
|
19
|
+
when options[:help] then Commands::Help
|
20
|
+
when options[:version] then Commands::Version
|
21
|
+
when options[:browse] then Commands::Browse
|
22
|
+
else Commands::Run
|
23
|
+
end
|
23
24
|
end
|
24
|
-
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
def options
|
27
|
+
Slop.parse(arguments, suppress_errors: true) do |opts|
|
28
|
+
opts.banner = "Usage: gem-search gem_name [options]\n"
|
29
|
+
sort_msg = detail_message([
|
30
|
+
"Sort by the field.",
|
31
|
+
"default [a]ll",
|
32
|
+
"[a]ll :DL(all) e.g.: gem-search webkit -s a",
|
33
|
+
"[v]er :DL(ver) e.g.: gem-search webkit -s v",
|
34
|
+
"[n]ame : e.g.: gem-search webkit -s n"
|
35
|
+
])
|
36
|
+
opts.string("-s", "--sort", sort_msg)
|
37
|
+
opts.string("-b", "--browse", "Open rubygem's homepage in the system's default web browser.")
|
38
|
+
opts.on("--no-homepage", "Do not show rubygems's homepage url.")
|
39
|
+
opts.on("-v", "--version", "Display the version.")
|
40
|
+
opts.on("-h", "--help", "Display this help message.")
|
41
|
+
end
|
41
42
|
end
|
42
|
-
|
43
|
-
memoize :options
|
43
|
+
memoize :options
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def detail_message(msgs)
|
46
|
+
indent = " " * 21
|
47
|
+
main = msgs[0]
|
48
|
+
detail = msgs[1..-1].map { |msg| "#{indent}#{msg}" }.join("\n")
|
49
|
+
"#{main}\n#{detail}"
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
data/lib/gem_search/commands.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module GemSearch
|
2
2
|
module Commands
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "gem_search/commands/base.rb"
|
4
|
+
require "gem_search/commands/browse.rb"
|
5
|
+
require "gem_search/commands/help.rb"
|
6
|
+
require "gem_search/commands/run.rb"
|
7
|
+
require "gem_search/commands/version.rb"
|
8
8
|
end
|
9
9
|
end
|
@@ -9,17 +9,17 @@ module GemSearch
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def puts_abort(args)
|
13
|
+
puts args
|
14
|
+
abort
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def unexpected_error(e)
|
18
|
+
puts "\nAn unexpected #{e.class} has occurred."
|
19
|
+
puts e.message
|
20
|
+
puts e.backtrace if ENV["DEBUG"]
|
21
|
+
abort
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "gem_search/utils/system_util"
|
2
2
|
|
3
3
|
module GemSearch
|
4
4
|
module Commands
|
@@ -10,24 +10,24 @@ module GemSearch
|
|
10
10
|
def call
|
11
11
|
gem_name = options[:browse]
|
12
12
|
result = Request.new.search_for_browse(gem_name)
|
13
|
-
url = extract_uri(result[
|
13
|
+
url = extract_uri(result["homepage_uri"], gem_name)
|
14
14
|
puts "Opening #{url}"
|
15
15
|
browser_open(url)
|
16
16
|
rescue OpenURI::HTTPError
|
17
|
-
puts_abort(
|
17
|
+
puts_abort("No such a gem.")
|
18
18
|
rescue => e
|
19
19
|
unexpected_error(e)
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def extract_uri(homepage_uri, gem_name)
|
25
|
+
if homepage_uri.nil? || homepage_uri.empty?
|
26
|
+
GEM_URL % gem_name
|
27
|
+
else
|
28
|
+
homepage_uri
|
29
|
+
end
|
29
30
|
end
|
30
|
-
end
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "gem_search/rendering"
|
2
2
|
module GemSearch
|
3
3
|
module Commands
|
4
4
|
class Run < Base
|
@@ -6,50 +6,50 @@ module GemSearch
|
|
6
6
|
include Rendering
|
7
7
|
|
8
8
|
ENABLE_SORT_OPTS = {
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
"a" => "downloads",
|
10
|
+
"n" => "name",
|
11
|
+
"v" => "version_downloads"
|
12
12
|
}
|
13
13
|
|
14
14
|
def call
|
15
15
|
puts_abort(options) unless valid?(options.arguments)
|
16
16
|
gems = search_gems
|
17
|
-
puts_abort(
|
17
|
+
puts_abort("We did not find results.") if gems.size.zero?
|
18
18
|
gems_sort!(gems)
|
19
|
-
render(gems, !options[
|
19
|
+
render(gems, !options["no-homepage"])
|
20
20
|
rescue => e
|
21
21
|
unexpected_error(e)
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
def valid?(arguments)
|
27
|
+
arguments.size > 0 && arguments.none? { |arg| arg.match(/\A-/) }
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def search_gems
|
31
|
+
print "Searching "
|
32
|
+
gems = Request.new.search(options.arguments[0]) do
|
33
|
+
print "."
|
34
|
+
end
|
35
|
+
puts
|
36
|
+
gems
|
34
37
|
end
|
35
|
-
puts
|
36
|
-
gems
|
37
|
-
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
def gems_sort!(gems)
|
40
|
+
if sort_opt == "name"
|
41
|
+
gems.sort! { |x, y| x[sort_opt] <=> y[sort_opt] }
|
42
|
+
else
|
43
|
+
gems.sort! { |x, y| y[sort_opt] <=> x[sort_opt] }
|
44
|
+
end
|
44
45
|
end
|
45
|
-
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
def sort_opt
|
48
|
+
sort_opt = options["sort"] ? ENABLE_SORT_OPTS[options["sort"][0].downcase] : nil
|
49
|
+
sort_opt = "downloads" unless sort_opt
|
50
|
+
sort_opt
|
51
|
+
end
|
52
|
+
memoize :sort_opt
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/lib/gem_search/rendering.rb
CHANGED
@@ -12,39 +12,39 @@ module GemSearch
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def ruled_line_size(gems)
|
16
|
+
@ruled_line_size = DEFAULT_RULED_LINE_SIZE.dup
|
17
|
+
max_name_size = gems.map { |gem| "#{gem['name']} (#{gem['version']})".size }.max
|
18
|
+
@ruled_line_size[0] = max_name_size if max_name_size > @ruled_line_size[0]
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
def render_header
|
22
|
+
f = @ruled_line_size
|
23
|
+
fmt = "%-#{f[0]}s %#{f[1]}s %#{f[2]}s"
|
24
|
+
titles = ["NAME", "DL(ver)", "DL(all)"]
|
25
|
+
hyphens = f[0, 3].map { |field| "-" * field }
|
26
|
+
if @has_homepage
|
27
|
+
fmt << " %-#{f[3]}s"
|
28
|
+
titles << "HOMEPAGE"
|
29
|
+
hyphens << "-" * f[3]
|
30
|
+
end
|
31
|
+
puts fmt % titles
|
32
|
+
puts fmt % hyphens
|
30
33
|
end
|
31
|
-
puts fmt % titles
|
32
|
-
puts fmt % hyphens
|
33
|
-
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
def render_body(gems)
|
36
|
+
f = @ruled_line_size
|
37
|
+
fmt = "%-#{f[0]}s %#{f[1]}d %#{f[2]}d"
|
38
|
+
fmt << " %-#{f[3]}s" if @has_homepage
|
39
|
+
gems.each do |gem|
|
40
|
+
columns = [
|
41
|
+
"#{gem['name']} (#{gem['version']})",
|
42
|
+
gem["version_downloads"],
|
43
|
+
gem["downloads"]
|
44
|
+
]
|
45
|
+
columns << gem["homepage_uri"] if @has_homepage
|
46
|
+
puts fmt % columns
|
47
|
+
end
|
47
48
|
end
|
48
|
-
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/gem_search/request.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "open-uri"
|
3
3
|
|
4
4
|
module GemSearch
|
5
5
|
class Request
|
@@ -30,21 +30,21 @@ module GemSearch
|
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def search_ended?(size)
|
34
|
+
size < MAX_GEMS_PER_PAGE || size.zero?
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
def request_ruby_gems_api(url)
|
38
|
+
option = {}
|
39
|
+
proxy = URI.parse(url).find_proxy
|
40
|
+
if proxy
|
41
|
+
if proxy.user && proxy.password
|
42
|
+
option[:proxy_http_basic_authentication] = [proxy, proxy.user, proxy.password]
|
43
|
+
else
|
44
|
+
option[:proxy] = proxy
|
45
|
+
end
|
45
46
|
end
|
47
|
+
JSON.parse(open(url, option).read)
|
46
48
|
end
|
47
|
-
JSON.parse(open(url, option).read)
|
48
|
-
end
|
49
49
|
end
|
50
50
|
end
|
@@ -2,19 +2,19 @@ module GemSearch::Utils
|
|
2
2
|
module SystemUtil
|
3
3
|
# https://github.com/github/hub/blob/9c589396ae38f7b9f98319065ad491149954c152/lib/hub/context.rb#L517
|
4
4
|
def browser_open(url)
|
5
|
-
cmd = osx? ?
|
5
|
+
cmd = osx? ? "open" : %w(xdg-open cygstart x-www-browser firefox opera mozilla netscape).find { |com| which com }
|
6
6
|
system(cmd, url)
|
7
7
|
end
|
8
8
|
|
9
9
|
# refer to: https://github.com/github/hub/blob/9c589396ae38f7b9f98319065ad491149954c152/lib/hub/context.rb#L527
|
10
10
|
def osx?
|
11
|
-
require
|
12
|
-
RbConfig::CONFIG[
|
11
|
+
require "rbconfig"
|
12
|
+
RbConfig::CONFIG["host_os"].to_s.include?("darwin")
|
13
13
|
end
|
14
14
|
|
15
15
|
def which(cmd)
|
16
|
-
exts = ENV[
|
17
|
-
ENV[
|
16
|
+
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
|
17
|
+
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
18
18
|
exts.each do |ext|
|
19
19
|
exe = "#{path}/#{cmd}#{ext}"
|
20
20
|
return exe if File.executable? exe
|
data/lib/gem_search/version.rb
CHANGED
data/spec/bin/gem_search_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
BIN =
|
1
|
+
BIN = "bin/gem-search"
|
2
2
|
|
3
3
|
USAGE = <<-EOS
|
4
4
|
Usage: gem-search gem_name [options]
|
@@ -14,31 +14,31 @@ Usage: gem-search gem_name [options]
|
|
14
14
|
-h, --help Display this help message.
|
15
15
|
EOS
|
16
16
|
|
17
|
-
RSpec.describe
|
18
|
-
shared_examples
|
19
|
-
it
|
17
|
+
RSpec.describe "bin/gem-search" do
|
18
|
+
shared_examples "display an usage" do
|
19
|
+
it "display an usage" do
|
20
20
|
should == USAGE
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context
|
24
|
+
context "with no argument" do
|
25
25
|
subject { `#{BIN}` }
|
26
|
-
it_behaves_like
|
26
|
+
it_behaves_like "display an usage"
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
29
|
+
context "with -h" do
|
30
30
|
subject { `#{BIN} -h` }
|
31
|
-
it_behaves_like
|
31
|
+
it_behaves_like "display an usage"
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
34
|
+
context "with -x(non-exisitng option)" do
|
35
35
|
subject { `#{BIN} -x` }
|
36
|
-
it_behaves_like
|
36
|
+
it_behaves_like "display an usage"
|
37
37
|
end
|
38
38
|
|
39
|
-
context
|
39
|
+
context "with -v" do
|
40
40
|
subject { `#{BIN} -v` }
|
41
|
-
it
|
41
|
+
it "display an usage" do
|
42
42
|
should == "gem-search #{GemSearch::VERSION}\n"
|
43
43
|
end
|
44
44
|
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
include GemSearch
|
2
2
|
|
3
3
|
RSpec.describe Commands::Browse do
|
4
|
-
describe
|
5
|
-
let(:query) {
|
4
|
+
describe "#call" do
|
5
|
+
let(:query) { "factory_girl" }
|
6
6
|
let(:options) { { browse: query } }
|
7
7
|
|
8
|
-
context
|
8
|
+
context "when a network error occurred" do
|
9
9
|
before do
|
10
10
|
stub_request(:get, build_gems_uri(query))
|
11
|
-
.to_return(status: 500, body:
|
11
|
+
.to_return(status: 500, body: "[]")
|
12
12
|
end
|
13
|
-
let(:query) {
|
13
|
+
let(:query) { "network_error_orccurred" }
|
14
14
|
it { expect { Commands::Browse.new(options).call }.to raise_error(Exception) }
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
17
|
+
context "when no matching gem" do
|
18
18
|
before { stub_request_gems_no_result(query) }
|
19
|
-
let(:query) {
|
19
|
+
let(:query) { "no_match_gem_name" }
|
20
20
|
it { expect { Commands::Browse.new(options).call }.to raise_error(SystemExit) }
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
23
|
+
context "when no homepage_uri" do
|
24
24
|
before do
|
25
25
|
http_stub = load_http_stubs("gems/#{query}.json")
|
26
26
|
stub_request_gems(query, http_stub)
|
27
27
|
end
|
28
|
-
let(:query) {
|
28
|
+
let(:query) { "git-trend_no_homepage" }
|
29
29
|
let(:uri) { Commands::Browse::GEM_URL % query }
|
30
|
-
it
|
30
|
+
it "open a rubygems uri" do
|
31
31
|
expect_any_instance_of(Kernel).to receive(:system).with(anything, uri)
|
32
32
|
Commands::Browse.new(options).call
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
36
|
+
context "when homepage_uri is existed" do
|
37
37
|
before do
|
38
38
|
http_stub = load_http_stubs("gems/#{query}.json")
|
39
|
-
@uri = JSON.parse(http_stub)[
|
39
|
+
@uri = JSON.parse(http_stub)["homepage_uri"]
|
40
40
|
stub_request_gems(query, http_stub)
|
41
41
|
end
|
42
|
-
let(:query) {
|
42
|
+
let(:query) { "git-trend" }
|
43
43
|
let(:uri) { @uri }
|
44
|
-
it
|
44
|
+
it "open a homepage uri" do
|
45
45
|
expect_any_instance_of(Kernel).to receive(:system).with(anything, uri)
|
46
46
|
Commands::Browse.new(options).call
|
47
47
|
end
|
data/spec/commands/run_spec.rb
CHANGED
@@ -1,60 +1,60 @@
|
|
1
1
|
include GemSearch
|
2
2
|
|
3
3
|
RSpec.describe Commands::Run do
|
4
|
-
shared_examples
|
5
|
-
before { allow(options).to receive(:[]).with(
|
6
|
-
it
|
4
|
+
shared_examples "sort example by all" do |sort_option|
|
5
|
+
before { allow(options).to receive(:[]).with("sort").and_return(sort_option) }
|
6
|
+
it "display rubygems sorted by DL(all)" do
|
7
7
|
expect { Commands::Run.new(options).call }.to output(dummy_search_result_sorted_by_all).to_stdout
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
shared_examples
|
12
|
-
before { allow(options).to receive(:[]).with(
|
13
|
-
it
|
11
|
+
shared_examples "sort example by ver" do |sort_option|
|
12
|
+
before { allow(options).to receive(:[]).with("sort").and_return(sort_option) }
|
13
|
+
it "display rubygems sorted by DL(ver)" do
|
14
14
|
expect { Commands::Run.new(options).call }.to output(dummy_search_result_sorted_by_ver).to_stdout
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
shared_examples
|
19
|
-
before { allow(options).to receive(:[]).with(
|
20
|
-
it
|
18
|
+
shared_examples "sort example by name" do |sort_option|
|
19
|
+
before { allow(options).to receive(:[]).with("sort").and_return(sort_option) }
|
20
|
+
it "display rubygems sorted by NAME" do
|
21
21
|
expect { Commands::Run.new(options).call }.to output(dummy_search_result_sorted_by_name).to_stdout
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
25
|
+
describe "#call" do
|
26
26
|
before do
|
27
27
|
allow(options).to receive(:arguments).and_return([query])
|
28
|
-
allow(options).to receive(:[]).with(
|
29
|
-
allow(options).to receive(:[]).with(
|
28
|
+
allow(options).to receive(:[]).with("no-homepage")
|
29
|
+
allow(options).to receive(:[]).with("sort")
|
30
30
|
end
|
31
|
-
let(:options) { double(
|
31
|
+
let(:options) { double("options") }
|
32
32
|
|
33
|
-
context
|
33
|
+
context "when a network error occurred" do
|
34
34
|
before do
|
35
35
|
stub_request(:get, build_search_uri(query, 1))
|
36
|
-
.to_return(status: 500, body:
|
36
|
+
.to_return(status: 500, body: "[]")
|
37
37
|
end
|
38
|
-
let(:query) {
|
38
|
+
let(:query) { "network_error_orccurred" }
|
39
39
|
it { expect { Commands::Run.new(options).call }.to raise_error(SystemExit) }
|
40
40
|
end
|
41
41
|
|
42
|
-
context
|
42
|
+
context "when no matching gem" do
|
43
43
|
before { stub_request_search_no_result_with_page(query, 1) }
|
44
|
-
let(:query) {
|
44
|
+
let(:query) { "no_matching_gem_name" }
|
45
45
|
it { expect { Commands::Run.new(options).call }.to raise_error(SystemExit) }
|
46
46
|
end
|
47
47
|
|
48
|
-
describe
|
48
|
+
describe "with no-homepage option" do
|
49
49
|
before do
|
50
|
-
allow(options).to receive(:[]).with(
|
50
|
+
allow(options).to receive(:[]).with("no-homepage").and_return(true)
|
51
51
|
stub_request_search(query, 1, dummy_search_result)
|
52
52
|
stub_request_search_no_result_with_page(query, 2)
|
53
53
|
end
|
54
|
-
let(:query) {
|
54
|
+
let(:query) { "factory_girl" }
|
55
55
|
|
56
|
-
context
|
57
|
-
it
|
56
|
+
context "with no sort option" do
|
57
|
+
it "display rubygems ordering by DL(all)" do
|
58
58
|
res = <<-'EOS'.unindent
|
59
59
|
|Searching .
|
60
60
|
|NAME DL(ver) DL(all)
|
@@ -68,86 +68,86 @@ RSpec.describe Commands::Run do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
71
|
+
describe "sorting" do
|
72
72
|
before do
|
73
73
|
stub_request_search(query, 1, dummy_search_result)
|
74
74
|
stub_request_search_no_result_with_page(query, 2)
|
75
75
|
end
|
76
|
-
let(:query) {
|
76
|
+
let(:query) { "factory_girl" }
|
77
77
|
|
78
|
-
describe
|
79
|
-
context
|
80
|
-
include_examples
|
78
|
+
describe "sort by all" do
|
79
|
+
context "with no sort option" do
|
80
|
+
include_examples "sort example by all", nil
|
81
81
|
end
|
82
82
|
|
83
|
-
context
|
84
|
-
include_examples
|
83
|
+
context "with disallowed sort option" do
|
84
|
+
include_examples "sort example by all", "xyz"
|
85
85
|
end
|
86
86
|
|
87
|
-
context
|
88
|
-
include_examples
|
87
|
+
context "with a" do
|
88
|
+
include_examples "sort example by all", "a"
|
89
89
|
end
|
90
90
|
|
91
|
-
context
|
92
|
-
include_examples
|
91
|
+
context "with all" do
|
92
|
+
include_examples "sort example by all", "all"
|
93
93
|
end
|
94
94
|
|
95
|
-
context
|
96
|
-
include_examples
|
95
|
+
context "with ALL" do
|
96
|
+
include_examples "sort example by all", "ALL"
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
describe
|
101
|
-
context
|
102
|
-
include_examples
|
100
|
+
describe "sort by ver" do
|
101
|
+
context "with v" do
|
102
|
+
include_examples "sort example by ver", "v"
|
103
103
|
end
|
104
104
|
|
105
|
-
context
|
106
|
-
include_examples
|
105
|
+
context "with ver" do
|
106
|
+
include_examples "sort example by ver", "ver"
|
107
107
|
end
|
108
108
|
|
109
|
-
context
|
110
|
-
include_examples
|
109
|
+
context "with VER" do
|
110
|
+
include_examples "sort example by ver", "VER"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
describe
|
115
|
-
context
|
116
|
-
include_examples
|
114
|
+
describe "sort by name" do
|
115
|
+
context "with n" do
|
116
|
+
include_examples "sort example by name", "n"
|
117
117
|
end
|
118
118
|
|
119
|
-
context
|
120
|
-
include_examples
|
119
|
+
context "with name" do
|
120
|
+
include_examples "sort example by name", "name"
|
121
121
|
end
|
122
122
|
|
123
|
-
context
|
124
|
-
include_examples
|
123
|
+
context "with NAME" do
|
124
|
+
include_examples "sort example by name", "NAME"
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
describe
|
129
|
+
describe "multiple page" do
|
130
130
|
before do
|
131
|
-
allow(options).to receive(:[]).with(
|
132
|
-
stub_request_search(query, 1, load_http_stubs(
|
133
|
-
stub_request_search(query, 2, load_http_stubs(
|
134
|
-
stub_request_search(query, 3, load_http_stubs(
|
131
|
+
allow(options).to receive(:[]).with("sort").and_return("name")
|
132
|
+
stub_request_search(query, 1, load_http_stubs("search/cucumber-_1.json"))
|
133
|
+
stub_request_search(query, 2, load_http_stubs("search/cucumber-_2.json"))
|
134
|
+
stub_request_search(query, 3, load_http_stubs("search/cucumber-_3.json"))
|
135
135
|
stub_request_search_no_result_with_page(query, 4)
|
136
136
|
end
|
137
|
-
let(:query) {
|
138
|
-
it
|
137
|
+
let(:query) { "cucumber-" }
|
138
|
+
it "display rubygems ordering by name" do
|
139
139
|
expect { Commands::Run.new(options).call }.to output(dummy_search_results_multiple_pages).to_stdout
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
describe
|
144
|
-
context
|
143
|
+
describe "ruled NAME line" do
|
144
|
+
context "NAME size is 42" do
|
145
145
|
before do
|
146
146
|
stub_request_search(query, 1, dummy_search_result_name_size_is_42)
|
147
147
|
stub_request_search_no_result_with_page(query, 2)
|
148
148
|
end
|
149
|
-
let(:query) {
|
150
|
-
it
|
149
|
+
let(:query) { "size_is_42_2345678901234567890123456789012" }
|
150
|
+
it "is 50 characters" do
|
151
151
|
# rubocop:disable Metrics/LineLength, Style/TrailingWhitespace
|
152
152
|
res = <<-'EOS'.unindent
|
153
153
|
|Searching .
|
@@ -161,13 +161,13 @@ RSpec.describe Commands::Run do
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
context
|
164
|
+
context "NAME size is 43" do
|
165
165
|
before do
|
166
166
|
stub_request_search(query, 1, dummy_search_result_name_size_is_43)
|
167
167
|
stub_request_search_no_result_with_page(query, 2)
|
168
168
|
end
|
169
|
-
let(:query) {
|
170
|
-
it
|
169
|
+
let(:query) { "size_is_43_23456789012345678901234567890123" }
|
170
|
+
it "is 51 characters" do
|
171
171
|
# rubocop:disable Metrics/LineLength, Style/TrailingWhitespace
|
172
172
|
res = <<-'EOS'.unindent
|
173
173
|
|Searching .
|
data/spec/helpers.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "rubygems"
|
3
|
+
require "simplecov"
|
4
4
|
SimpleCov.start
|
5
5
|
|
6
|
-
require
|
6
|
+
require "webmock/rspec"
|
7
7
|
# require 'pry'
|
8
|
-
require
|
8
|
+
require "gem_search"
|
9
9
|
|
10
|
-
require
|
10
|
+
require "helpers"
|
11
11
|
|
12
12
|
RSpec.configure do |config|
|
13
13
|
config.include Helpers
|
@@ -24,13 +24,13 @@ RSpec.configure do |config|
|
|
24
24
|
config.run_all_when_everything_filtered = true
|
25
25
|
config.expose_dsl_globally = false
|
26
26
|
|
27
|
-
config.example_status_persistence_file_path =
|
27
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
28
28
|
config.order = :random
|
29
29
|
Kernel.srand config.seed
|
30
30
|
end
|
31
31
|
|
32
32
|
def load_http_stubs(file_name)
|
33
|
-
open(File.join(File.dirname(__FILE__),
|
33
|
+
open(File.join(File.dirname(__FILE__), "http_stubs", file_name)).read
|
34
34
|
end
|
35
35
|
|
36
36
|
# stubs for search API
|
@@ -39,7 +39,7 @@ def stub_request_search(query, page, body)
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def stub_request_search_no_result_with_page(query, page)
|
42
|
-
stub_request(:get, build_search_uri(query, page)).to_return(status: 200, body:
|
42
|
+
stub_request(:get, build_search_uri(query, page)).to_return(status: 200, body: "[]")
|
43
43
|
end
|
44
44
|
|
45
45
|
def build_search_uri(query, page)
|
@@ -52,7 +52,7 @@ def stub_request_gems(query, body)
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def stub_request_gems_no_result(query)
|
55
|
-
stub_request(:get, build_gems_uri(query)).to_return(status: 404, body:
|
55
|
+
stub_request(:get, build_gems_uri(query)).to_return(status: 404, body: "[]")
|
56
56
|
end
|
57
57
|
|
58
58
|
def build_gems_uri(query)
|
@@ -61,6 +61,6 @@ end
|
|
61
61
|
|
62
62
|
class String
|
63
63
|
def unindent
|
64
|
-
gsub(/^\s+\|/,
|
64
|
+
gsub(/^\s+\|/, "")
|
65
65
|
end
|
66
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rochefort
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.4.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
26
|
+
version: 4.4.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mem
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,56 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 2.1.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 2.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 11.
|
61
|
+
version: 11.3.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 11.
|
68
|
+
version: 11.3.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: 3.5.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: 3.5.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.12.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.12.0
|
97
97
|
description: search gems with using rubygems.org API
|
98
98
|
email:
|
99
99
|
- terasawan@gmail.com
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.6.6
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: search gems with using rubygems.org API
|