spec/git_trend/cli_spec.rb in git-trend-1.3.0 vs spec/git_trend/cli_spec.rb in git-trend-1.4.0
- old
+ new
@@ -1,8 +1,8 @@
-# rubocop:disable Style/TrailingWhitespace
-include GitTrend
RSpec.describe GitTrend::CLI do
+ include GitTrend
+
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
@@ -23,40 +23,45 @@
let(:cli) { CLI.new }
describe "with -n option" do
context "with 3" do
before { stub_request_get("trending") }
+
let(:number) { 3 }
+
it "display top 3 daily ranking" do
- res = <<-'EOS'.unindent
+ res = <<-OUTPUT.unindent
|No. Name Lang Star
|--- ---------------------------------------- ---------------- ------
| 1 linexjlin/GPTs 445
| 2 ml-explore/mlx-examples Python 161
| 3 PRIS-CV/DemoFusion Jupyter Notebook 169
- EOS
+ OUTPUT
expect { cli.invoke(:list, [], number: number, description: false) }.to output(res).to_stdout
end
end
context "with over 25" do
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
end
end
end
describe "with -l option" do
context "with ruby" do
before { stub_request_get("trending/#{language}") }
+
let(:language) { "ruby" }
it "display daily ranking by language" do
- res = <<-'EOS'.unindent
+ res = <<-OUTPUT.unindent
|No. Name Lang Star
|--- ---------------------------------------- ---------- ------
| 1 greatghoul/remote-working Ruby 34
| 2 huginn/huginn Ruby 13
| 3 jekyll/jekyll Ruby 11
@@ -81,37 +86,40 @@
| 22 forem/forem Ruby 4
| 23 urbanadventurer/WhatWeb Ruby 3
| 24 chef/chef Ruby 0
| 25 instructure/canvas-lms Ruby 0
- EOS
+ OUTPUT
expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout
end
end
context "with alloy : when trending is nothing" do
before { stub_request_get("trending/#{language}") }
+
let(:language) { "alloy" }
it "display the 0cases message" do
- res = <<-'EOS'.unindent
+ res = <<-OUTPUT.unindent
|It looks like we don’t have any trending repositories.
- EOS
+ OUTPUT
expect { cli.invoke(:list, [], language: language, description: false) }.to output(res).to_stdout
end
end
end
describe "with -s option" do
context "with no option" do
before { stub_request_get("trending?since=") }
+
include_examples "since daily ranking", ""
end
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
@@ -123,10 +131,11 @@
end
end
describe "since weekly" do
before { stub_request_get("trending?since=weekly") }
+
context "with w" do
include_examples "since weekly ranking", "w"
end
context "with week" do
@@ -138,10 +147,11 @@
end
end
describe "since monthly" do
before { stub_request_get("trending?since=monthly") }
+
context "with m" do
include_examples "since monthly ranking", "m"
end
context "with month" do
@@ -191,15 +201,16 @@
end
describe "with -l and -s option" do
context "with ruby and weekly" do
before { stub_request_get("trending/#{language}?since=#{since}") }
+
let(:language) { "ruby" }
let(:since) { "weekly" }
it "display weekly ranking by language" do
- res = <<-'EOS'.unindent
+ res = <<-OUTPUT.unindent
|No. Name Lang Star
|--- ---------------------------------------- ---------- ------
| 1 mastodon/mastodon Ruby 115
| 2 community/community Ruby 25
| 3 freeCodeCamp/devdocs Ruby 65
@@ -224,43 +235,46 @@
| 22 tradingview/charting-library-examples Ruby 3
| 23 kaminari/kaminari Ruby 5
| 24 rubocop/rubocop Ruby 10
| 25 paper-trail-gem/paper_trail Ruby 3
- EOS
+ OUTPUT
expect { cli.invoke(:list, [], language: language, since: since, description: false) }.to output(res).to_stdout
end
end
end
end
describe "#languages" do
before { stub_request_get("trending") }
+
let(:cli) { CLI.new }
context "with no option" do
it "display languages" do
- expect { cli.languages }.to output(match("C++").and match("HTML").and match("Ruby")).to_stdout
+ expect { cli.languages }.to output(include("C++", "HTML", "Ruby")).to_stdout
end
end
end
private
+
def stub_request_get(stub_url_path, stub_file_name = nil)
url = Scraper::BASE_HOST.dup
url << "/#{stub_url_path}" if stub_url_path
uri = URI.parse(url)
stub_file = stub_file_name || stub_url_path
stub_request(:get, uri)
.to_return(
status: 200,
headers: { content_type: "text/html" },
- body: load_http_stub(stub_file))
+ body: load_http_stub(stub_file)
+ )
end
def dummy_result_without_description
- <<-'EOS'.unindent
+ <<-OUTPUT.unindent
|No. Name Lang Star
|--- ------------------------------------------ ---------------- ------
| 1 linexjlin/GPTs 445
| 2 ml-explore/mlx-examples Python 161
| 3 PRIS-CV/DemoFusion Jupyter Notebook 169
@@ -285,15 +299,15 @@
| 22 facebookresearch/Pearl Python 95
| 23 zzzgydi/clash-verge TypeScript 31
| 24 ytdl-org/youtube-dl Python 24
| 25 dunglas/frankenphp Go 53
- EOS
+ OUTPUT
end
def dummy_result_no_options
- <<-'EOS'.unindent
+ <<-OUTPUT.unindent
|No. Name Lang Star Description
|--- ------------------------------------------ ---------------- ------ ---------------------------------------------------------------------
| 1 linexjlin/GPTs 445 leaked prompts of GPTs
| 2 ml-explore/mlx-examples Python 161 Examples in the MLX framework
| 3 PRIS-CV/DemoFusion Jupyter Notebook 169 Let us democratise high-resolution generation! (arXiv 2023)
@@ -318,15 +332,15 @@
| 22 facebookresearch/Pearl Python 95 A Production-ready Reinforcement Learning AI Agent Library brought...
| 23 zzzgydi/clash-verge TypeScript 31 A Clash GUI based on tauri. Supports Windows, macOS and Linux.
| 24 ytdl-org/youtube-dl Python 24 Command-line program to download videos from YouTube.com and other...
| 25 dunglas/frankenphp Go 53 The modern PHP app server
- EOS
+ OUTPUT
end
def dummy_weekly_result
- <<-'EOS'.unindent
+ <<-OUTPUT.unindent
|No. Name Lang Star
|--- ------------------------------------------ ---------------- ------
| 1 LC044/WeChatMsg Python 10719
| 2 microsoft/TaskWeaver Python 1957
| 3 facebookresearch/seamless_communication C 1568
@@ -351,15 +365,15 @@
| 22 awesome-selfhosted/awesome-selfhosted 2239
| 23 upscayl/upscayl TypeScript 266
| 24 coolsnowwolf/lede C 132
| 25 QwenLM/Qwen Python 377
- EOS
+ OUTPUT
end
def dummy_monthly_result
- <<-'EOS'.unindent
+ <<-OUTPUT.unindent
|No. Name Lang Star
|--- ---------------------------------------- ---------------- ------
| 1 SawyerHood/draw-a-ui TypeScript 11761
| 2 Stability-AI/generative-models Python 7286
| 3 microsoft/ML-For-Beginners HTML 9252
@@ -384,8 +398,8 @@
| 22 saadeghi/daisyui Svelte 1773
| 23 nlohmann/json C++ 1080
| 24 SillyTavern/SillyTavern JavaScript 1566
| 25 1Panel-dev/1Panel Go 1950
- EOS
+ OUTPUT
end
end