Skip to content

Commit

Permalink
Remove old-ruby relateted code
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Oct 13, 2024
1 parent 120610d commit 25a5fc0
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 173 deletions.
25 changes: 7 additions & 18 deletions lib/coverband/collectors/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ module Collectors
class Coverage
include Singleton

def self.ruby_version_greater_than_or_equal_to?(version)
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version)
end

def reset_instance
@project_directory = File.expand_path(Coverband.configuration.root)
@ignore_patterns = Coverband.configuration.ignore
Expand Down Expand Up @@ -87,7 +83,6 @@ def filtered_files(new_results)

def initialize
@semaphore = Mutex.new
raise NotImplementedError, "Coverage needs Ruby > 2.3.0" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3.0")

require "coverage"
if RUBY_PLATFORM == "java"
Expand All @@ -98,20 +93,14 @@ def initialize
if defined?(SimpleCov) && defined?(Rails) && defined?(Rails.env) && Rails.env.test?
puts "Coverband: detected SimpleCov in test Env, allowing it to start Coverage"
puts "Coverband: to ensure no error logs or missing Coverage call `SimpleCov.start` prior to requiring Coverband"
else
if ::Coverage.respond_to?(:state)
if ::Coverage.state == :idle
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage)
elsif ::Coverage.state == :suspended
::Coverage.resume
end
elsif Coverage.ruby_version_greater_than_or_equal_to?("2.6.0")
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage) unless ::Coverage.running?
elsif Coverage.ruby_version_greater_than_or_equal_to?("2.5.0")
::Coverage.start unless ::Coverage.running?
else
::Coverage.start
elsif ::Coverage.respond_to?(:state)
if ::Coverage.state == :idle
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage)
elsif ::Coverage.state == :suspended
::Coverage.resume
end
else
::Coverage.start(oneshot_lines: Coverband.configuration.use_oneshot_lines_coverage) unless ::Coverage.running?
end
reset_instance
end
Expand Down
17 changes: 2 additions & 15 deletions lib/coverband/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Configuration
:reporter, :redis_namespace, :redis_ttl,
:background_reporting_enabled,
:test_env, :web_enable_clear, :gem_details, :web_debug, :report_on_exit,
:simulate_oneshot_lines_coverage,
:use_oneshot_lines_coverage, :simulate_oneshot_lines_coverage,
:view_tracker, :defer_eager_loading_data,
:track_routes, :track_redirect_routes, :route_tracker,
:track_translations, :translations_tracker,
Expand All @@ -22,7 +22,7 @@ class Configuration
:background_reporting_sleep_seconds, :reporting_wiggle,
:send_deferred_eager_loading_data, :paged_reporting

attr_reader :track_gems, :ignore, :use_oneshot_lines_coverage
attr_reader :track_gems, :ignore

#####
# TODO: This is is brittle and not a great solution to avoid deploy time
Expand Down Expand Up @@ -252,19 +252,6 @@ def to_h
end
end

def use_oneshot_lines_coverage=(value)
unless one_shot_coverage_implemented_in_ruby_version? || !value
raise(StandardError,
"One shot line coverage is only available in ruby >= 2.6")
end

@use_oneshot_lines_coverage = value
end

def one_shot_coverage_implemented_in_ruby_version?
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
end

def redis_url
@redis_url ||= ENV["COVERBAND_REDIS_URL"] || ENV["REDIS_URL"]
end
Expand Down
42 changes: 0 additions & 42 deletions test/coverband/collectors/coverage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,4 @@ def teardown
::Coverage.expects(:resume)
Coverband::Collectors::Coverage.send(:new)
end

test "one shot line coverage disabled for ruby >= 2.6" do
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
::Coverage.expects(:respond_to?).returns(false)

Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(true)
::Coverage.expects(:running?).returns(false)
::Coverage.expects(:start).with(oneshot_lines: false)
Coverband::Collectors::Coverage.send(:new)
end

test "one shot line coverage enabled for ruby >= 2.6" do
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
::Coverage.expects(:respond_to?).returns(false)

Coverband.configuration.expects(:use_oneshot_lines_coverage).returns(true)
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(true)
::Coverage.expects(:running?).returns(false)
::Coverage.expects(:start).with(oneshot_lines: true)
Coverband::Collectors::Coverage.send(:new)
end

test "one shot line coverage for ruby >= 2.6 when already running" do
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
::Coverage.expects(:respond_to?).returns(false)

Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(true)
::Coverage.expects(:running?).returns(true)
::Coverage.expects(:start).never
Coverband::Collectors::Coverage.send(:new)
end

test "no one shot line coverage for ruby < 2.6" do
return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0")
::Coverage.expects(:respond_to?).returns(false)

Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.6.0").returns(false)
Coverband::Collectors::Coverage.expects(:ruby_version_greater_than_or_equal_to?).with("2.5.0").returns(true)
::Coverage.expects(:running?).returns(false)
::Coverage.expects(:start).with
Coverband::Collectors::Coverage.send(:new)
end
end
50 changes: 24 additions & 26 deletions test/coverband/collectors/delta_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,33 @@ def setup
assert_equal({"car.rb" => [nil, 0, 2, 0]}, results)
end

if Coverband.configuration.one_shot_coverage_implemented_in_ruby_version?
test "oneshot coverage calls clear" do
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
current_coverage = {
"car.rb" => [1, 5]
}
test "oneshot coverage calls clear" do
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
current_coverage = {
"car.rb" => [1, 5]
}

::Coverage.expects(:result).with(clear: true, stop: false).returns(current_coverage)
Coverband::Collectors::Delta::RubyCoverage.results
end
::Coverage.expects(:result).with(clear: true, stop: false).returns(current_coverage)
Coverband::Collectors::Delta::RubyCoverage.results
end

test "one shot lines results" do
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
current_coverage = {}
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
assert_equal(current_coverage, results)
test "one shot lines results" do
Coverband.configuration.stubs(:use_oneshot_lines_coverage).returns(true)
current_coverage = {}
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
assert_equal(current_coverage, results)

current_coverage = {
"dealership.rb" => {
oneshot_lines: [2, 3]
}
}
Coverband::Collectors::Delta.class_variable_set(:@@project_directory, "dealership.rb")
::Coverage.expects(:line_stub).with("dealership.rb").returns([nil, 0, 0, nil])
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
expected = {
"dealership.rb" => [nil, 1, 1, nil]
current_coverage = {
"dealership.rb" => {
oneshot_lines: [2, 3]
}
assert_equal(expected, results)
end
}
Coverband::Collectors::Delta.class_variable_set(:@@project_directory, "dealership.rb")
::Coverage.expects(:line_stub).with("dealership.rb").returns([nil, 0, 0, nil])
results = Coverband::Collectors::Delta.results(mock_coverage(current_coverage))
expected = {
"dealership.rb" => [nil, 1, 1, nil]
}
assert_equal(expected, results)
end
end
18 changes: 0 additions & 18 deletions test/coverband/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,4 @@ def setup
config.redis_url = "redis://localhost:3333"
end
end

test "use_oneshot_lines_coverage" do
refute Coverband.configuration.use_oneshot_lines_coverage

Coverband.configuration.stubs(:one_shot_coverage_implemented_in_ruby_version?).returns(true)
Coverband.configuration.use_oneshot_lines_coverage = true
assert Coverband.configuration.use_oneshot_lines_coverage

Coverband.configuration.use_oneshot_lines_coverage = false
refute Coverband.configuration.use_oneshot_lines_coverage

Coverband.configuration.stubs(:one_shot_coverage_implemented_in_ruby_version?).returns(false)
exception = assert_raises Exception do
Coverband.configuration.use_oneshot_lines_coverage = true
end
assert_equal "One shot line coverage is only available in ruby >= 2.6", exception.message
refute Coverband.configuration.use_oneshot_lines_coverage
end
end
106 changes: 52 additions & 54 deletions test/coverband/reporters/web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,73 @@

ENV["RACK_ENV"] = "test"

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
module Coverband
class WebTest < Minitest::Test
include Rack::Test::Methods
module Coverband
class WebTest < Minitest::Test
include Rack::Test::Methods

def app
Coverband::Reporters::Web.new
end
def app
Coverband::Reporters::Web.new
end

def teardown
super
end
def teardown
super
end

test "renders index content" do
get "/"
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end
test "renders index content" do
get "/"
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end

test "renders index content for empty path" do
get ""
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end
test "renders index content for empty path" do
get ""
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end

test "renders 404" do
get "/show"
assert last_response.not_found?
assert_equal "404 error!", last_response.body
end
test "renders 404" do
get "/show"
assert last_response.not_found?
assert_equal "404 error!", last_response.body
end

test "clears coverband" do
post "/clear"
assert_equal 302, last_response.status
end
test "clears coverband" do
post "/clear"
assert_equal 302, last_response.status
end
end
end

module Coverband
class AuthWebTest < Minitest::Test
include Rack::Test::Methods
module Coverband
class AuthWebTest < Minitest::Test
include Rack::Test::Methods

def setup
super
@store = Coverband.configuration.store
Coverband.configure do |config|
config.password = "test_pass"
end
def setup
super
@store = Coverband.configuration.store
Coverband.configure do |config|
config.password = "test_pass"
end
end

def app
Coverband::Reporters::Web.new
end
def app
Coverband::Reporters::Web.new
end

def teardown
super
end
def teardown
super
end

test "renders index with basic auth" do
basic_authorize "anything", "test_pass"
get "/"
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end
test "renders index with basic auth" do
basic_authorize "anything", "test_pass"
get "/"
assert last_response.ok?
assert_match "Coverband Home", last_response.body
end

test "renders 401 auth error when not provided" do
get "/"
assert_equal 401, last_response.status
end
test "renders 401 auth error when not provided" do
get "/"
assert_equal 401, last_response.status
end
end
end

0 comments on commit 25a5fc0

Please sign in to comment.