spec/git_trend/cli_spec.rb in git-trend-0.2.3 vs spec/git_trend/cli_spec.rb in git-trend-1.0.0

- old
+ new

@@ -1,57 +1,57 @@ -# encoding: utf-8 -require 'spec_helper' - include GitTrend +RSpec.describe GitTrend::CLI do + shared_examples 'since daily ranking' do |since| + it 'display daily ranking' do + expect { cli.invoke(:list, [], since: since, description: false) }.to output(dummy_result_without_description).to_stdout + end + end -RSpec.shared_examples_for 'since daily ranking' do - it 'display daily ranking' do - expect { @cli.invoke(:list, [], since: since, description: false) }.to output(dummy_result_without_description).to_stdout + shared_examples 'since weekly ranking' do |since| + it 'display weekly ranking' do + expect { cli.invoke(:list, [], since: since, description: false) }.to output(dummy_weekly_result).to_stdout + end end -end -RSpec.describe GitTrend::CLI do - describe '#list' do - before do - @cli = CLI.new + shared_examples 'since monthly ranking' do |since| + it 'display monthly ranking' do + expect { cli.invoke(:list, [], since: since, description: false) }.to output(dummy_monthly_result).to_stdout end + end + describe '#list' do + let(:cli) { CLI.new } + describe 'with -n option' do context 'with 3' do - before do - stub_request_get('trending') - end + before { stub_request_get('trending') } let(:number) { 3 } - it 'display daily ranking top 3' do + it 'display top 3 daily ranking' do res = <<-'EOS'.unindent |No. Name Lang Star |--- ---------------------------------------- ---------- ------ | 1 HunterLarco/voxel.css CSS 941 | 2 fengyuanchen/viewerjs JavaScript 716 | 3 FreeCodeCamp/FreeCodeCamp JavaScript 614 EOS - expect { @cli.invoke(:list, [], number: number, description: false) }.to output(res).to_stdout + expect { cli.invoke(:list, [], number: number, description: false) }.to output(res).to_stdout end end context 'with over 25' do - before do - stub_request_get('trending') - end + before { stub_request_get('trending') } let(:number) { 26 } it 'display daily ranking' do - expect { @cli.invoke(:list, [], number: number, description: false) }.to output(dummy_result_without_description).to_stdout + expect { cli.invoke(:list, [], number: number, description: false) }.to output(dummy_result_without_description).to_stdout end end end describe 'with -l option' do context 'with ruby' do - before do - stub_request_get("trending?l=#{language}") - end + before { stub_request_get("trending?l=#{language}") } let(:language) { 'ruby' } it 'display daily ranking by language' do res = <<-'EOS'.unindent |No. Name Lang Star @@ -81,18 +81,16 @@ | 23 thoughtbot/administrate Ruby 7 | 24 capistrano/capistrano Ruby 7 | 25 brandonhilkert/sucker_punch Ruby 7 EOS - expect { @cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout + expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout end end context 'with objective-c++ (including + sign)' do - before do - stub_request_get('trending?l=objective-c%2B%2B') - end + before { stub_request_get('trending?l=objective-c%2B%2B') } let(:language) { 'objective-c++' } it 'display daily ranking by language' do res = <<-'EOS'.unindent |No. Name Lang Star @@ -122,100 +120,64 @@ | 23 swift2js/swift2js Objective-C++ 0 | 24 Smartype/iOS_VPNPlugIn Objective-C++ 0 | 25 ryanb93/Applefy Objective-C++ 0 EOS - expect { @cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout + expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout end end end describe 'with -s option' do - before { stub_request_get("trending?since=#{since}") } - context 'with no option' do - let(:since) { '' } - it_behaves_like 'since daily ranking' + before { stub_request_get('trending?since=') } + include_examples 'since daily ranking', '' end - context 'with daily' do - let(:since) { 'daily' } - it_behaves_like 'since daily ranking' + describe 'since daily' do + before { stub_request_get('trending?since=daily') } + context 'with d' do + include_examples 'since daily ranking', 'd' + end + + context 'with day' do + include_examples 'since daily ranking', 'day' + end + + context 'with daily' do + include_examples 'since daily ranking', 'daily' + end end - context 'with weekly' do - let(:since) { 'weekly' } - it 'display daily ranking since weekly' do - res = <<-'EOS'.unindent - |No. Name Lang Star - |--- ---------------------------------------- ----------- ------ - | 1 DrkSephy/es6-cheatsheet JavaScript 5143 - | 2 FreeCodeCamp/FreeCodeCamp JavaScript 4555 - | 3 Microsoft/CNTK C++ 3548 - | 4 jiahaog/nativefier JavaScript 2593 - | 5 HunterLarco/voxel.css CSS 2054 - | 6 samshadwell/TrumpScript Python 1824 - | 7 Yalantis/uCrop Java 1731 - | 8 Soundnode/soundnode-app JavaScript 1230 - | 9 tensorflow/tensorflow C++ 953 - | 10 Jam3/devtool JavaScript 1170 - | 11 KnuffApp/Knuff Objective-C 1136 - | 12 brave/browser-laptop JavaScript 1030 - | 13 nlf/dlite Go 1051 - | 14 zquestz/s Go 971 - | 15 milligram/milligram CSS 959 - | 16 themattrix/bash-concurrent Shell 924 - | 17 kragniz/json-sempai Python 871 - | 18 loverajoel/jstips CSS 841 - | 19 chinchang/hint.css CSS 816 - | 20 hirak/prestissimo PHP 783 - | 21 rdpeng/ProgrammingAssignment2 R 8 - | 22 fengyuanchen/viewerjs JavaScript 729 - | 23 vhf/free-programming-books 620 - | 24 yamartino/pressure JavaScript 695 - | 25 cdmedia/cms.js JavaScript 677 + describe 'since weekly' do + before { stub_request_get('trending?since=weekly') } + context 'with w' do + include_examples 'since weekly ranking', 'w' + end - EOS - expect { @cli.invoke(:list, [], since: since, description: false) }.to output(res).to_stdout + context 'with week' do + include_examples 'since weekly ranking', 'week' end + + context 'with weekly' do + include_examples 'since weekly ranking', 'weekly' + end end - context 'with monthly' do - let(:since) { 'monthly' } - it 'display daily ranking since monthly' do - res = <<-'EOS'.unindent - |No. Name Lang Star - |--- ------------------------------------------ ----------- ------ - | 1 FreeCodeCamp/FreeCodeCamp JavaScript 15567 - | 2 loverajoel/jstips CSS 7710 - | 3 braydie/HowToBeAProgrammer 6786 - | 4 DrkSephy/es6-cheatsheet JavaScript 5127 - | 5 matryer/bitbar Objective-C 4946 - | 6 Microsoft/ChakraCore JavaScript 4689 - | 7 VerbalExpressions/JSVerbalExpressions JavaScript 4758 - | 8 tldr-pages/tldr Shell 4193 - | 9 jlevy/the-art-of-command-line 3966 - | 10 mhinz/vim-galore VimL 4062 - | 11 jiahaog/nativefier JavaScript 3932 - | 12 jlevy/og-equity-compensation 3797 - | 13 Microsoft/CNTK C++ 3537 - | 14 hacksalot/HackMyResume JavaScript 3252 - | 15 vhf/free-programming-books 2690 - | 16 milligram/milligram CSS 2876 - | 17 samshadwell/TrumpScript Python 2718 - | 18 sindresorhus/awesome 2640 - | 19 donnemartin/data-science-ipython-notebooks Python 2424 - | 20 tensorflow/tensorflow C++ 2033 - | 21 os-js/OS.js JavaScript 2357 - | 22 JakeLin/IBAnimatable Swift 2345 - | 23 viljamis/feature.js HTML 2239 - | 24 facebook/react-native Java 1962 - | 25 baidu-research/warp-ctc Cuda 1966 + describe 'since monthly' do + before { stub_request_get('trending?since=monthly') } + context 'with m' do + include_examples 'since monthly ranking', 'm' + end - EOS - expect { @cli.invoke(:list, [], since: since, description: false) }.to output(res).to_stdout + context 'with month' do + include_examples 'since monthly ranking', 'month' end + + context 'with monthly' do + include_examples 'since monthly ranking', 'monthly' + end end end describe 'with -d option (or with no option)' do after do @@ -229,41 +191,39 @@ ENV['LINES'] = '40' end context 'with no option' do it 'display daily ranking' do - expect { @cli.invoke(:list, []) }.to output(dummy_result_no_options).to_stdout + expect { cli.invoke(:list, []) }.to output(dummy_result_no_options).to_stdout end end context 'terminal width is enough' do it 'display daily ranking with description' do - expect { @cli.invoke(:list, [], description: true) }.to output(dummy_result_no_options).to_stdout + expect { cli.invoke(:list, [], description: true) }.to output(dummy_result_no_options).to_stdout end end context 'terminal width is tiny' do before do ENV['COLUMNS'] = '84' # it is not enough for description. ENV['LINES'] = '40' end it 'display daily ranking about the same as no option' do - expect { @cli.invoke(:list, [], description: true) }.to output(dummy_result_without_description).to_stdout + expect { cli.invoke(:list, [], description: true) }.to output(dummy_result_without_description).to_stdout end end end describe 'with -l and -s option' do context 'with ruby and weekly' do - before do - stub_request_get("trending?l=#{language}&since=#{since}") - end + before { stub_request_get("trending?l=#{language}&since=#{since}") } let(:language) { 'ruby' } let(:since) { 'weekly' } - it 'display daily ranking since weekly' do + it 'display weekly ranking by language' do res = <<-'EOS'.unindent |No. Name Lang Star |--- ---------------------------------------- ---------- ------ | 1 Homebrew/homebrew Ruby 166 | 2 shakacode/react_on_rails Ruby 197 @@ -290,11 +250,11 @@ | 23 sass/sass Ruby 53 | 24 kilimchoi/engineering-blogs Ruby 53 | 25 thoughtbot/administrate Ruby 48 EOS - expect { @cli.invoke(:list, [], language: language, since: since, description: false) }.to output(res).to_stdout + expect { cli.invoke(:list, [], language: language, since: since, description: false) }.to output(res).to_stdout end end end describe 'without options' do @@ -303,343 +263,33 @@ ENV['COLUMNS'] = '140' ENV['LINES'] = '40' stub_request_get('trending', 'trending_including_multibyte_characters') end it 'display daily ranking' do - expect { @cli.invoke(:list, []) }.to output(dummy_result_no_options_with_multibyte_characters).to_stdout + expect { cli.invoke(:list, []) }.to output(dummy_result_no_options_with_multibyte_characters).to_stdout end end end end describe '#languages' do - before do - @cli = CLI.new - stub_request_get('trending') - end + before { stub_request_get('trending') } + let(:cli) { CLI.new } context 'with no option' do - it 'display daily ranking' do - res = <<-'EOS'.unindent - |ABAP - |ActionScript - |Ada - |Agda - |AGS Script - |Alloy - |AMPL - |ANTLR - |ApacheConf - |Apex - |API Blueprint - |APL - |AppleScript - |Arc - |Arduino - |ASP - |AspectJ - |Assembly - |ATS - |Augeas - |AutoHotkey - |AutoIt - |Awk - |Batchfile - |Befunge - |Bison - |BitBake - |BlitzBasic - |BlitzMax - |Bluespec - |Boo - |Brainfuck - |Brightscript - |Bro - |C - |C# - |C++ - |Cap'n Proto - |CartoCSS - |Ceylon - |Chapel - |Charity - |ChucK - |Cirru - |Clarion - |Clean - |Click - |CLIPS - |Clojure - |CMake - |COBOL - |CoffeeScript - |ColdFusion - |Common Lisp - |Component Pascal - |Cool - |Coq - |Crystal - |CSS - |Cucumber - |Cuda - |Cycript - |D - |Darcs Patch - |Dart - |Diff - |DIGITAL Command Language - |DM - |Dogescript - |DTrace - |Dylan - |E - |Eagle - |eC - |ECL - |Eiffel - |Elixir - |Elm - |Emacs Lisp - |EmberScript - |Erlang - |F# - |Factor - |Fancy - |Fantom - |FLUX - |Forth - |FORTRAN - |FreeMarker - |Frege - |Game Maker Language - |GAMS - |GAP - |GDScript - |Genshi - |Gettext Catalog - |GLSL - |Glyph - |Gnuplot - |Go - |Golo - |Gosu - |Grace - |Grammatical Framework - |Groff - |Groovy - |Hack - |Handlebars - |Harbour - |Haskell - |Haxe - |HCL - |HTML - |Hy - |HyPhy - |IDL - |Idris - |IGOR Pro - |Inform 7 - |Inno Setup - |Io - |Ioke - |Isabelle - |J - |Jasmin - |Java - |JavaScript - |JFlex - |JSONiq - |Julia - |Jupyter Notebook - |KiCad - |Kit - |Kotlin - |KRL - |LabVIEW - |Lasso - |Lean - |Lex - |LilyPond - |Limbo - |Liquid - |LiveScript - |LLVM - |Logos - |Logtalk - |LOLCODE - |LookML - |LoomScript - |LSL - |Lua - |M - |Makefile - |Mako - |Markdown - |Mask - |Mathematica - |Matlab - |Max - |MAXScript - |Mercury - |Metal - |MiniD - |Mirah - |Modelica - |Modula-2 - |Module Management System - |Monkey - |Moocode - |MoonScript - |MTML - |mupad - |Myghty - |NCL - |Nemerle - |nesC - |NetLinx - |NetLinx+ERB - |NetLogo - |NewLisp - |Nginx - |Nimrod - |Nit - |Nix - |NSIS - |Nu - |Objective-C - |Objective-C++ - |Objective-J - |OCaml - |Omgrofl - |ooc - |Opa - |Opal - |OpenEdge ABL - |OpenSCAD - |Ox - |Oxygene - |Oz - |Pan - |Papyrus - |Parrot - |Pascal - |PAWN - |Perl - |Perl6 - |PHP - |PicoLisp - |PigLatin - |Pike - |PLpgSQL - |PLSQL - |PogoScript - |Pony - |PostScript - |PowerShell - |Processing - |Prolog - |Propeller Spin - |Protocol Buffer - |Puppet - |Pure Data - |PureBasic - |PureScript - |Python - |QMake - |QML - |R - |Racket - |Ragel in Ruby Host - |RAML - |RDoc - |REALbasic - |Rebol - |Red - |Redcode - |RenderScript - |RobotFramework - |Rouge - |Ruby - |Rust - |SaltStack - |SAS - |Scala - |Scheme - |Scilab - |Self - |Shell - |ShellSession - |Shen - |Slash - |Smali - |Smalltalk - |Smarty - |SMT - |SourcePawn - |SQF - |SQL - |SQLPL - |Squirrel - |Stan - |Standard ML - |Stata - |SuperCollider - |Swift - |SystemVerilog - |Tcl - |Tea - |TeX - |Thrift - |Turing - |TXL - |TypeScript - |UnrealScript - |UrWeb - |Vala - |VCL - |Verilog - |VHDL - |VimL - |Visual Basic - |Volt - |Vue - |Web Ontology Language - |WebIDL - |wisp - |X10 - |xBase - |XC - |XML - |Xojo - |XPages - |XProc - |XQuery - |XS - |XSLT - |Xtend - |Yacc - |Zephir - |Zimpl - | - |300 languages - |you can get only selected language list with '-l' option. - |if languages is unknown, you can specify 'unkown'. - | - EOS - expect { @cli.languages }.to output(res).to_stdout + it 'display languages' do + expect { cli.languages }.to output(dummy_languages).to_stdout end end end private def stub_request_get(stub_url, stub_file_name = nil) url = Scraper::BASE_HOST.dup url << "/#{stub_url}" if stub_url uri = URI.parse(url) - stub_file = stub_file_name || stub_url stub_request(:get, uri) .to_return( status: 200, headers: { content_type: 'text/html' }, @@ -740,8 +390,384 @@ | 22 fengyuanchen/cropperjs JavaScript 95 JavaScript image cropper. | 23 proflin/CoolplaySpark 85 酷玩 Spark | 24 incrediblesound/story-graph JavaScript 87 The Graph that Generates Stories | 25 geeeeeeeeek/WeChatLuckyMoney Java 75 微信抢红包插件, an Android app that helps you snatch virtual red envelopes... + EOS + end + + def dummy_weekly_result + <<-'EOS'.unindent + |No. Name Lang Star + |--- ---------------------------------------- ----------- ------ + | 1 DrkSephy/es6-cheatsheet JavaScript 5143 + | 2 FreeCodeCamp/FreeCodeCamp JavaScript 4555 + | 3 Microsoft/CNTK C++ 3548 + | 4 jiahaog/nativefier JavaScript 2593 + | 5 HunterLarco/voxel.css CSS 2054 + | 6 samshadwell/TrumpScript Python 1824 + | 7 Yalantis/uCrop Java 1731 + | 8 Soundnode/soundnode-app JavaScript 1230 + | 9 tensorflow/tensorflow C++ 953 + | 10 Jam3/devtool JavaScript 1170 + | 11 KnuffApp/Knuff Objective-C 1136 + | 12 brave/browser-laptop JavaScript 1030 + | 13 nlf/dlite Go 1051 + | 14 zquestz/s Go 971 + | 15 milligram/milligram CSS 959 + | 16 themattrix/bash-concurrent Shell 924 + | 17 kragniz/json-sempai Python 871 + | 18 loverajoel/jstips CSS 841 + | 19 chinchang/hint.css CSS 816 + | 20 hirak/prestissimo PHP 783 + | 21 rdpeng/ProgrammingAssignment2 R 8 + | 22 fengyuanchen/viewerjs JavaScript 729 + | 23 vhf/free-programming-books 620 + | 24 yamartino/pressure JavaScript 695 + | 25 cdmedia/cms.js JavaScript 677 + + EOS + end + + def dummy_monthly_result + <<-'EOS'.unindent + |No. Name Lang Star + |--- ------------------------------------------ ----------- ------ + | 1 FreeCodeCamp/FreeCodeCamp JavaScript 15567 + | 2 loverajoel/jstips CSS 7710 + | 3 braydie/HowToBeAProgrammer 6786 + | 4 DrkSephy/es6-cheatsheet JavaScript 5127 + | 5 matryer/bitbar Objective-C 4946 + | 6 Microsoft/ChakraCore JavaScript 4689 + | 7 VerbalExpressions/JSVerbalExpressions JavaScript 4758 + | 8 tldr-pages/tldr Shell 4193 + | 9 jlevy/the-art-of-command-line 3966 + | 10 mhinz/vim-galore VimL 4062 + | 11 jiahaog/nativefier JavaScript 3932 + | 12 jlevy/og-equity-compensation 3797 + | 13 Microsoft/CNTK C++ 3537 + | 14 hacksalot/HackMyResume JavaScript 3252 + | 15 vhf/free-programming-books 2690 + | 16 milligram/milligram CSS 2876 + | 17 samshadwell/TrumpScript Python 2718 + | 18 sindresorhus/awesome 2640 + | 19 donnemartin/data-science-ipython-notebooks Python 2424 + | 20 tensorflow/tensorflow C++ 2033 + | 21 os-js/OS.js JavaScript 2357 + | 22 JakeLin/IBAnimatable Swift 2345 + | 23 viljamis/feature.js HTML 2239 + | 24 facebook/react-native Java 1962 + | 25 baidu-research/warp-ctc Cuda 1966 + + EOS + end + + def dummy_languages + <<-'EOS'.unindent + |ABAP + |ActionScript + |Ada + |Agda + |AGS Script + |Alloy + |AMPL + |ANTLR + |ApacheConf + |Apex + |API Blueprint + |APL + |AppleScript + |Arc + |Arduino + |ASP + |AspectJ + |Assembly + |ATS + |Augeas + |AutoHotkey + |AutoIt + |Awk + |Batchfile + |Befunge + |Bison + |BitBake + |BlitzBasic + |BlitzMax + |Bluespec + |Boo + |Brainfuck + |Brightscript + |Bro + |C + |C# + |C++ + |Cap'n Proto + |CartoCSS + |Ceylon + |Chapel + |Charity + |ChucK + |Cirru + |Clarion + |Clean + |Click + |CLIPS + |Clojure + |CMake + |COBOL + |CoffeeScript + |ColdFusion + |Common Lisp + |Component Pascal + |Cool + |Coq + |Crystal + |CSS + |Cucumber + |Cuda + |Cycript + |D + |Darcs Patch + |Dart + |Diff + |DIGITAL Command Language + |DM + |Dogescript + |DTrace + |Dylan + |E + |Eagle + |eC + |ECL + |Eiffel + |Elixir + |Elm + |Emacs Lisp + |EmberScript + |Erlang + |F# + |Factor + |Fancy + |Fantom + |FLUX + |Forth + |FORTRAN + |FreeMarker + |Frege + |Game Maker Language + |GAMS + |GAP + |GDScript + |Genshi + |Gettext Catalog + |GLSL + |Glyph + |Gnuplot + |Go + |Golo + |Gosu + |Grace + |Grammatical Framework + |Groff + |Groovy + |Hack + |Handlebars + |Harbour + |Haskell + |Haxe + |HCL + |HTML + |Hy + |HyPhy + |IDL + |Idris + |IGOR Pro + |Inform 7 + |Inno Setup + |Io + |Ioke + |Isabelle + |J + |Jasmin + |Java + |JavaScript + |JFlex + |JSONiq + |Julia + |Jupyter Notebook + |KiCad + |Kit + |Kotlin + |KRL + |LabVIEW + |Lasso + |Lean + |Lex + |LilyPond + |Limbo + |Liquid + |LiveScript + |LLVM + |Logos + |Logtalk + |LOLCODE + |LookML + |LoomScript + |LSL + |Lua + |M + |Makefile + |Mako + |Markdown + |Mask + |Mathematica + |Matlab + |Max + |MAXScript + |Mercury + |Metal + |MiniD + |Mirah + |Modelica + |Modula-2 + |Module Management System + |Monkey + |Moocode + |MoonScript + |MTML + |mupad + |Myghty + |NCL + |Nemerle + |nesC + |NetLinx + |NetLinx+ERB + |NetLogo + |NewLisp + |Nginx + |Nimrod + |Nit + |Nix + |NSIS + |Nu + |Objective-C + |Objective-C++ + |Objective-J + |OCaml + |Omgrofl + |ooc + |Opa + |Opal + |OpenEdge ABL + |OpenSCAD + |Ox + |Oxygene + |Oz + |Pan + |Papyrus + |Parrot + |Pascal + |PAWN + |Perl + |Perl6 + |PHP + |PicoLisp + |PigLatin + |Pike + |PLpgSQL + |PLSQL + |PogoScript + |Pony + |PostScript + |PowerShell + |Processing + |Prolog + |Propeller Spin + |Protocol Buffer + |Puppet + |Pure Data + |PureBasic + |PureScript + |Python + |QMake + |QML + |R + |Racket + |Ragel in Ruby Host + |RAML + |RDoc + |REALbasic + |Rebol + |Red + |Redcode + |RenderScript + |RobotFramework + |Rouge + |Ruby + |Rust + |SaltStack + |SAS + |Scala + |Scheme + |Scilab + |Self + |Shell + |ShellSession + |Shen + |Slash + |Smali + |Smalltalk + |Smarty + |SMT + |SourcePawn + |SQF + |SQL + |SQLPL + |Squirrel + |Stan + |Standard ML + |Stata + |SuperCollider + |Swift + |SystemVerilog + |Tcl + |Tea + |TeX + |Thrift + |Turing + |TXL + |TypeScript + |UnrealScript + |UrWeb + |Vala + |VCL + |Verilog + |VHDL + |VimL + |Visual Basic + |Volt + |Vue + |Web Ontology Language + |WebIDL + |wisp + |X10 + |xBase + |XC + |XML + |Xojo + |XPages + |XProc + |XQuery + |XS + |XSLT + |Xtend + |Yacc + |Zephir + |Zimpl + | + |300 languages + |you can get only selected language list with '-l' option. + |if languages is unknown, you can specify 'unkown'. + | EOS end end