spec/git_trend_spec.rb in git-trend-1.3.0 vs spec/git_trend_spec.rb in git-trend-1.4.0
- old
+ new
@@ -1,82 +1,98 @@
RSpec.describe GitTrend do
+ include described_class
+ let(:scraper_mock) { instance_double(Scraper) }
+
before do
+ allow(Scraper).to receive(:new).and_return(scraper_mock)
stub_request(:get, /.*/)
.to_return(status: 200, headers: { content_type: "text/html" }, body: load_http_stub("trending"))
end
describe "#get" do
- context "without options" do
- it "Scraper#get call without options" do
- expect_any_instance_of(Scraper).to receive(:get).with(no_args)
- GitTrend.get
+ context "normal" do
+ before do
+ allow(scraper_mock).to receive(:get)
end
- end
- context "parameter is 'ruby'" do
- it "Scraper#get call with 'ruby'" do
- expect_any_instance_of(Scraper).to receive(:get).with("ruby")
- GitTrend.get("ruby")
+ context "without options" do
+ it "Scraper#get call without options" do
+ described_class.get
+ expect(scraper_mock).to have_received(:get).with(no_args)
+ end
end
- end
- context "parameter is :ruby" do
- it "Scraper#get call with :ruby" do
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby)
- GitTrend.get(:ruby)
+ context "parameter is 'ruby'" do
+ it "Scraper#get call with 'ruby'" do
+ described_class.get("ruby")
+ expect(scraper_mock).to have_received(:get).with("ruby")
+ end
end
- end
- context "parameter is since: :weekly" do
- it "Scraper#get call with [nil, :weekly]" do
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :weekly)
- GitTrend.get(since: :weekly)
+ context "parameter is :ruby" do
+ it "Scraper#get call with :ruby" do
+ described_class.get(:ruby)
+ expect(scraper_mock).to have_received(:get).with(:ruby)
+ end
end
- end
- context "parameter is since: :week" do
- it "Scraper#get call with [nil, :week]" do
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :week)
- GitTrend.get(since: :week)
+ context "parameter is since: :weekly" do
+ it "Scraper#get call with [nil, :weekly]" do
+ described_class.get(since: :weekly)
+ expect(scraper_mock).to have_received(:get).with(nil, :weekly)
+ end
end
- end
- context "parameter is since: :w" do
- it "Scraper#get call with [nil, :w]" do
- expect_any_instance_of(Scraper).to receive(:get).with(nil, :w)
- GitTrend.get(since: :w)
+ context "parameter is since: :week" do
+ it "Scraper#get call with [nil, :week]" do
+ described_class.get(since: :week)
+ expect(scraper_mock).to have_received(:get).with(nil, :week)
+ end
end
- end
- context "parameters are 'ruby', 'weekly'" do
- it "Scraper#get call with ['ruby', 'weekly']" do
- expect_any_instance_of(Scraper).to receive(:get).with("ruby", "weekly")
- GitTrend.get("ruby", "weekly")
+ context "parameter is since: :w" do
+ it "Scraper#get call with [nil, :w]" do
+ described_class.get(since: :w)
+ expect(scraper_mock).to have_received(:get).with(nil, :w)
+ end
end
- end
- context "parameters are :ruby, :weekly" do
- it "Scraper#get call with [:ruby, :weekly]" do
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby, :weekly)
- GitTrend.get(:ruby, :weekly)
+ context "parameters are 'ruby', 'weekly'" do
+ it "Scraper#get call with ['ruby', 'weekly']" do
+ described_class.get("ruby", "weekly")
+ expect(scraper_mock).to have_received(:get).with("ruby", "weekly")
+ end
end
- end
- context "parameters are language: :ruby, since: :weekly" do
- it "Scraper#get call with [:ruby, :weekly]" do
- expect_any_instance_of(Scraper).to receive(:get).with(:ruby, :weekly)
- GitTrend.get(language: :ruby, since: :weekly)
+ context "parameters are :ruby, :weekly" do
+ it "Scraper#get call with [:ruby, :weekly]" do
+ described_class.get(:ruby, :weekly)
+ expect(scraper_mock).to have_received(:get).with(:ruby, :weekly)
+ end
end
+
+ context "parameters are language: :ruby, since: :weekly" do
+ it "Scraper#get call with [:ruby, :weekly]" do
+ described_class.get(language: :ruby, since: :weekly)
+ expect(scraper_mock).to have_received(:get).with(:ruby, :weekly)
+ end
+ end
end
- context "when too many parameters" do
- it { expect { GitTrend.get("ruby", "weekly", "many_params") }.to raise_error(Exception) }
+ context "abnormal" do
+ context "when too many parameters" do
+ it { expect { described_class.get("ruby", "weekly", "many_params") }.to raise_error(Exception) }
+ end
end
describe "#languages" do
+ before do
+ allow(scraper_mock).to receive(:languages)
+ end
+
it "Scraper#languages call" do
- expect_any_instance_of(Scraper).to receive(:languages).with(no_args)
- GitTrend.languages
+ described_class.languages
+ expect(scraper_mock).to have_received(:languages).with(no_args)
end
end
end
end