Skip to content

Commit

Permalink
fix/refactoring for simplecov setup reporting less coverage than what…
Browse files Browse the repository at this point in the history
…'s actually covered
  • Loading branch information
ddnexus committed Apr 10, 2021
1 parent 5e6ecf1 commit fc614bd
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 78 deletions.
17 changes: 11 additions & 6 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
if ENV['RUN_SIMPLECOV'] == 'true'
SimpleCov.command_name 'main'
SimpleCov.start do
add_filter %r{^/test/}
add_group 'Core', %w[lib/pagy.rb lib/pagy/backend.rb lib/pagy/frontend.rb ]
add_group 'Extras', %w[lib/pagy/countless.rb lib/pagy/extras]
SimpleCov.start do
if ENV['RUN_CODECOV'] == 'true'
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
elsif ENV['SILENT_SIMPLECOV'] == 'true'
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
end
SimpleCov.command_name "Task##{$PROCESS_ID}"
SimpleCov.merge_timeout 20
add_group 'Core', %w[lib/pagy.rb lib/pagy/countless.rb lib/pagy/backend.rb lib/pagy/frontend.rb lib/pagy/exceptions.rb]
add_group 'Extras', 'lib/pagy/extras'
add_group 'Tests', 'test'
end
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

gemspec
# gemspec

gem 'i18n'
gem 'oj', require: false # false is for testing with or without it
Expand All @@ -18,7 +18,7 @@ group :test do
gem 'rubocop-rake', require: false
gem 'rubocop-minitest', require: false
gem 'simplecov', require: false
end
end

group :apps do
gem 'sinatra'
Expand Down
6 changes: 0 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
PATH
remote: .
specs:
pagy (4.1.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -97,7 +92,6 @@ DEPENDENCIES
minitest
minitest-reporters
oj
pagy!
puma
rack
rake
Expand Down
22 changes: 12 additions & 10 deletions test/mock_helpers/elasticsearch_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def records
@raw_response['hits']['hits'].map{|r| "R-#{r}"}
end

def count
@raw_response['hits']['hits'].size
end
# unused by current testing
# def count
# @raw_response['hits']['hits'].size
# end

end

Expand Down Expand Up @@ -72,13 +73,14 @@ def initialize(query, options={})
@response = {'hits' => {'hits' => @search.results, 'total' => RESULTS[query].size}}
end

def records
@response['hits']['hits'].map{|r| "R-#{r}"}
end

def count
@response['hits']['hits'].size
end
# unused by current testing
# def records
# @response['hits']['hits'].map{|r| "R-#{r}"}
# end
#
# def count
# @response['hits']['hits'].size
# end

end

Expand Down
41 changes: 15 additions & 26 deletions test/pagy/exceptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_relative '../test_helper'


describe Pagy::VariableError do

describe '#variable and #value' do
Expand Down Expand Up @@ -31,34 +30,24 @@
end

it 'raises for other variables' do
begin
Pagy.new(count: -10)
rescue Pagy::VariableError => e
_(e.variable).must_equal :count
_(e.value).must_equal(-10)
end
begin
Pagy.new(count: 'string')
rescue Pagy::VariableError => e
_(e.variable).must_equal :count
_(e.value).must_equal 'string'
end
Pagy.new(count: -10)
rescue Pagy::VariableError => e
_(e.variable).must_equal :count
_(e.value).must_equal(-10)
end

it 'rescues as ArgumentError (backward compatible)' do
begin
Pagy.new(count: 1, page: -10)
rescue ArgumentError => e
_(e.variable).must_equal :page
_(e.value).must_equal(-10)
end
it 'rescues as ArgumentError' do
Pagy.new(count: 1, page: -10)
rescue ArgumentError => e
_(e.variable).must_equal :page
_(e.value).must_equal(-10)
end

begin
Pagy.new(count: 'string')
rescue ArgumentError => e
_(e.variable).must_equal :count
_(e.value).must_equal 'string'
end
it 'does not raise for :count and :offset set to arbitrary strings (converted to 0)' do
pagy = Pagy.new(count: 'string', outset: 'string')
_(pagy).must_be_instance_of Pagy
_(pagy.count).must_equal 0
_(pagy.instance_variable_get(:@outset)).must_equal 0
end

end
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/elasticsearch_rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require_relative '../../mock_helpers/elasticsearch_rails'
require 'pagy/extras/overflow'

SimpleCov.command_name 'elasticsearch' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::ElasticsearchRails do

describe '#pagy_search' do
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'i18n'
require 'pagy/extras/i18n'

SimpleCov.command_name 'i18n' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::Frontend do

let(:view) { MockView.new }
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/items_and_countless_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'pagy/extras/countless'
require 'pagy/extras/items'

SimpleCov.command_name 'items' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::Backend do

describe "#pagy_get_vars and #pagy_countless_get_vars" do
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/items_and_elasticsearch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
require_relative '../../mock_helpers/searchkick'
require 'pagy/extras/items'

SimpleCov.command_name 'items' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::Backend do

describe "#pagy_get_vars and #pagy_countless_get_vars" do
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/overflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require_relative '../../test_helper'
require 'pagy/extras/overflow'

SimpleCov.command_name 'overflow' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy do

let(:vars) {{ page: 100, count: 103, items: 10, size: [3, 2, 2, 3] }}
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/searchkick_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require_relative '../../mock_helpers/searchkick'
require 'pagy/extras/overflow'

SimpleCov.command_name 'elasticsearch' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::Searchkick do

describe '#pagy_search' do
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/shared_combo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'pagy/extras/items'
require 'pagy/extras/trim'

SimpleCov.command_name 'shared_combo' if ENV['RUN_SIMPLECOV'] == 'true'

# add tests for oj and pagy_id
describe Pagy::Frontend do

Expand Down
3 changes: 0 additions & 3 deletions test/pagy/extras/shared_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
require 'oj' # all the other tests run without Oj
require 'pagy/extras/shared'

SimpleCov.command_name 'shared' if ENV['RUN_SIMPLECOV'] == 'true'

# add tests for oj and pagy_id
describe Pagy::Frontend do

let(:view) { MockView.new('http://example.com:3000/foo?') }
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
require 'pagy/extras/support'
require 'pagy/countless'

SimpleCov.command_name 'support' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::Frontend do

let(:view) { MockView.new }
Expand Down
2 changes: 0 additions & 2 deletions test/pagy/extras/trim_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
require 'pagy/extras/semantic'
require 'pagy/extras/trim'

SimpleCov.command_name 'trim' if ENV['RUN_SIMPLECOV'] == 'true'

describe Pagy::Frontend do

let(:view) { MockView.new }
Expand Down
7 changes: 0 additions & 7 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

require 'simplecov' if ENV['RUN_SIMPLECOV'] == 'true'

if ENV['RUN_CODECOV'] == 'true'
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
elsif ENV['SILENT_SIMPLECOV'] == 'true'
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
end

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)

require 'pagy'
Expand Down

0 comments on commit fc614bd

Please sign in to comment.