[rubygems/rubygems] Prefer assert_predicate over mere assert

https://github.com/rubygems/rubygems/commit/0d10063824
This commit is contained in:
Nobuyoshi Nakada 2023-06-21 17:44:16 +09:00 committed by git
parent 67ab8b4346
commit a651903a86

View File

@ -68,7 +68,7 @@ class TestUpdateSuggestion < Gem::TestCase
def test_eglible_for_update
with_eglible_environment(cmd: @cmd) do
Time.stub :now, 123_456_789 do
assert @cmd.eglible_for_update?
assert_predicate @cmd, :eglible_for_update?
assert_equal 123_456_789, Gem.configuration.last_update_check
# test last check is written to config file
@ -85,7 +85,7 @@ class TestUpdateSuggestion < Gem::TestCase
# is not released yet and stored
with_eglible_environment(cmd: @cmd, rubygems_version: current_version, latest_rubygems_version: latest_version) do
Time.stub :now, @start_time do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
assert_equal @start_time, Gem.configuration.last_update_check
end
end
@ -99,7 +99,7 @@ class TestUpdateSuggestion < Gem::TestCase
reset_last_update_check: false
) do
Time.stub :now, @start_time + @week do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
assert_equal @start_time + @week, Gem.configuration.last_update_check
end
end
@ -116,7 +116,7 @@ class TestUpdateSuggestion < Gem::TestCase
reset_last_update_check: false
) do
Time.stub :now, @start_time + @week + @minute do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
assert_equal @start_time + @week, Gem.configuration.last_update_check
end
end
@ -126,19 +126,19 @@ class TestUpdateSuggestion < Gem::TestCase
with_eglible_environment(cmd: @cmd) do
# checking for first time, it is eglible and stored
Time.stub :now, @start_time do
assert @cmd.eglible_for_update?
assert_predicate @cmd, :eglible_for_update?
assert_equal @start_time, Gem.configuration.last_update_check
end
# checking minute later is not eglible and not stored
Time.stub :now, @start_time + @minute do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
assert_equal @start_time, Gem.configuration.last_update_check
end
# checking week later is eglible again and stored
Time.stub :now, @start_time + @week do
assert @cmd.eglible_for_update?
assert_predicate @cmd, :eglible_for_update?
assert_equal @start_time + @week, Gem.configuration.last_update_check
end
end
@ -148,7 +148,7 @@ class TestUpdateSuggestion < Gem::TestCase
with_eglible_environment(cmd: @cmd) do
original_config = Gem.configuration[:prevent_update_suggestion]
Gem.configuration[:prevent_update_suggestion] = true
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
ensure
Gem.configuration[:prevent_update_suggestion] = original_config
end
@ -158,7 +158,7 @@ class TestUpdateSuggestion < Gem::TestCase
with_eglible_environment(cmd: @cmd) do
original_env = ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"]
ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = "yes"
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
ensure
ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = original_env
end
@ -166,13 +166,13 @@ class TestUpdateSuggestion < Gem::TestCase
def test_eglible_for_update_non_tty
with_eglible_environment(tty: false, cmd: @cmd) do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
end
end
def test_eglible_for_update_for_prerelease
with_eglible_environment(rubygems_version: Gem::Version.new("1.0.0-rc1"), cmd: @cmd) do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
end
end
@ -180,7 +180,7 @@ class TestUpdateSuggestion < Gem::TestCase
with_eglible_environment(cmd: @cmd) do
original_disable = Gem.disable_system_update_message
Gem.disable_system_update_message = "disabled"
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
ensure
Gem.disable_system_update_message = original_disable
end
@ -188,14 +188,14 @@ class TestUpdateSuggestion < Gem::TestCase
def test_eglible_for_update_on_ci
with_eglible_environment(ci: true, cmd: @cmd) do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
end
end
def test_eglible_for_update_unwrittable_config
with_eglible_environment(cmd: @cmd) do
Gem.configuration.stub :state_file_writable?, false do
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
end
end
end
@ -203,7 +203,7 @@ class TestUpdateSuggestion < Gem::TestCase
def test_eglible_for_update_notification_delay
with_eglible_environment(cmd: @cmd) do
Gem.configuration.last_update_check = Time.now.to_i
refute @cmd.eglible_for_update?
refute_predicate @cmd, :eglible_for_update?
end
end
end