Skip to content

Commit

Permalink
[rubygems/rubygems] Prefer assert_predicate over mere assert
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Jun 22, 2023
1 parent 67ab8b4 commit a651903
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/rubygems/test_gem_update_suggestion.rb
Expand Up @@ -68,7 +68,7 @@ def test_update_suggestion
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
Expand All @@ -85,7 +85,7 @@ def test_eglible_for_update_is_not_annoying_when_new_version_is_released
# 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
Expand All @@ -99,7 +99,7 @@ def test_eglible_for_update_is_not_annoying_when_new_version_is_released
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
Expand All @@ -116,7 +116,7 @@ def test_eglible_for_update_is_not_annoying_when_new_version_is_released
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
Expand All @@ -126,19 +126,19 @@ def test_eglible_for_update_is_not_annoying_when_not_upgraded
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
Expand All @@ -148,7 +148,7 @@ def test_eglible_for_update_prevent_config
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
Expand All @@ -158,52 +158,52 @@ def test_eglible_for_update_prevent_env
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
end

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

def test_eglible_for_update_disabled_update
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
end

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

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

0 comments on commit a651903

Please sign in to comment.