Skip to content

Commit

Permalink
use actionable code coverage (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser authored and ddnexus committed Jun 1, 2018
1 parent bee3fec commit 6168df3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -285,6 +286,7 @@ DEPENDENCIES
rack
rake (~> 10.0)
rubocop (~> 0.55.0)
single_cov
slim

BUNDLED WITH
Expand Down
42 changes: 40 additions & 2 deletions test/pagy/frontend_test.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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(
'<nav class="pagy-nav pagination" role="navigation" aria-label="pager">' \
'<span class="page prev"><a href="/foo?page=9" rel="prev" aria-label="previous">&lsaquo;&nbsp;Prev</a></span> ' \
'<span class="page"><a href="/foo?page=1">1</a></span> ' \
'<span class="page gap">&hellip;</span> ' \
'<span class="page"><a href="/foo?page=6">6</a></span> ' \
'<span class="page"><a href="/foo?page=7">7</a></span> ' \
'<span class="page"><a href="/foo?page=8">8</a></span> ' \
'<span class="page"><a href="/foo?page=9" rel="prev">9</a></span> ' \
'<span class="page active">10</span> ' \
'<span class="page"><a href="/foo?page=11" rel="next">11</a></span> ' \
'<span class="page"><a href="/foo?page=12">12</a></span> ' \
'<span class="page"><a href="/foo?page=13">13</a></span> ' \
'<span class="page"><a href="/foo?page=14">14</a></span> ' \
'<span class="page gap">&hellip;</span> ' \
'<span class="page"><a href="/foo?page=50">50</a></span> ' \
'<span class="page next"><a href="/foo?page=11" rel="next" aria-label="next">Next&nbsp;&rsaquo;</a></span></nav>',
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 '<a href="/foo?page=1" X>1</a>'
end
end

describe "#pagy_t" do
Expand Down Expand Up @@ -125,5 +164,4 @@ def test_render_info_with_existing_118n_key
assert_equal "Displaying Products <b>41-60</b> of <b>100</b> in total", frontend.pagy_info(pagy)
end
end

end
2 changes: 2 additions & 0 deletions test/pagy_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require_relative 'test_helper'

SingleCov.covered!

describe Pagy do
let(:pagy) { Pagy.new count: 100, page: 4 }

Expand Down
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 6168df3

Please sign in to comment.