From 6168df35055ce29c08f8037ae6fbb4744c57526c Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Thu, 31 May 2018 21:53:14 -0700 Subject: [PATCH] use actionable code coverage (#29) --- Gemfile | 1 + Gemfile.lock | 2 ++ test/pagy/frontend_test.rb | 42 ++++++++++++++++++++++++++++++++++++-- test/pagy_test.rb | 2 ++ test/test_helper.rb | 5 +++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index fa07ccd57..a78debc04 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,7 @@ gem 'benchmark-ips' gem 'kalibera' gem 'memory_profiler' gem 'rubocop', '~> 0.55.0' # needs to be fixed since it constantly adds new cops +gem 'single_cov' gem "github-pages", group: :jekyll_plugins diff --git a/Gemfile.lock b/Gemfile.lock index 33309e4c8..12669a0e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -257,6 +257,7 @@ GEM sawyer (0.8.1) addressable (>= 2.3.5, < 2.6) faraday (~> 0.8, < 1.0) + single_cov (1.0.3) slim (3.0.9) temple (>= 0.7.6, < 0.9) tilt (>= 1.3.3, < 2.1) @@ -285,6 +286,7 @@ DEPENDENCIES rack rake (~> 10.0) rubocop (~> 0.55.0) + single_cov slim BUNDLED WITH diff --git a/test/pagy/frontend_test.rb b/test/pagy/frontend_test.rb index 6390b1fcf..796e5272b 100644 --- a/test/pagy/frontend_test.rb +++ b/test/pagy/frontend_test.rb @@ -1,8 +1,9 @@ require_relative '../test_helper' require 'rack' -describe Pagy::Frontend do +SingleCov.covered! +describe Pagy::Frontend do class TestView include Pagy::Frontend @@ -71,6 +72,44 @@ def test_pagy_nav_page_6 frontend.pagy_nav(pagy) ) end + + def test_pagy_nav_page_10 + @array = (1..1000).to_a.extend(Pagy::Array::PageMethod) + pagy, _ = @array.pagy(10) + + assert_equal( + '', + frontend.pagy_nav(pagy) + ) + end + + def test_link_extras + pagy, _ = @array.pagy(1, link_extra: "X") + frontend.pagy_nav(pagy).must_include '?page=2" X rel' + end + end + + describe "#pagy_link_proc" do + it "renders with extras" do + @array = (1..103).to_a.extend(Pagy::Array::PageMethod) + pagy, _ = @array.pagy(1) + frontend.pagy_link_proc(pagy, "X").call(1).must_equal '1' + end end describe "#pagy_t" do @@ -125,5 +164,4 @@ def test_render_info_with_existing_118n_key assert_equal "Displaying Products 41-60 of 100 in total", frontend.pagy_info(pagy) end end - end diff --git a/test/pagy_test.rb b/test/pagy_test.rb index 23acd7c38..414359153 100644 --- a/test/pagy_test.rb +++ b/test/pagy_test.rb @@ -1,5 +1,7 @@ require_relative 'test_helper' +SingleCov.covered! + describe Pagy do let(:pagy) { Pagy.new count: 100, page: 4 } diff --git a/test/test_helper.rb b/test/test_helper.rb index f5dd8d23d..435f9079a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,8 @@ +require 'bundler/setup' + +require 'single_cov' +SingleCov.setup :minitest + $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) require 'pagy' require_relative 'array'