diff options
author | Josef Šimánek <josef.simanek@gmail.com> | 2022-11-04 22:56:31 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-11-11 17:24:08 +0900 |
commit | de159c5a855dd53bfd9ce284c9099306724560a7 (patch) | |
tree | 5e184f264bb1930a14aa7db4f487828ef70788b7 /test/rubygems | |
parent | 7ce0f81fbbd9c2b35e9fe35f5ef040626e284a88 (diff) |
[rubygems/rubygems] Store last check even when upgrade is not available and fix test.
https://github.com/rubygems/rubygems/commit/bcffc2b0a5
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6715
Diffstat (limited to 'test/rubygems')
-rw-r--r-- | test/rubygems/test_gem_update_suggestion.rb | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/test/rubygems/test_gem_update_suggestion.rb b/test/rubygems/test_gem_update_suggestion.rb index ba54059ee7..520a69ac69 100644 --- a/test/rubygems/test_gem_update_suggestion.rb +++ b/test/rubygems/test_gem_update_suggestion.rb @@ -9,6 +9,9 @@ class TestUpdateSuggestion < Gem::TestCase @cmd = Gem::Command.new "dummy", "dummy" @cmd.extend Gem::UpdateSuggestion + @start_time = 1_000_000 + @minute = 60 * 60 + @week = 7 * 24 * @minute end def with_eglible_environment(**params) @@ -22,12 +25,13 @@ class TestUpdateSuggestion < Gem::TestCase rubygems_version: Gem::Version.new("1.2.3"), latest_rubygems_version: Gem::Version.new("2.0.0"), ci: false, + reset_last_update_check: true, cmd: ) original_config, Gem.configuration[:prevent_update_suggestion] = Gem.configuration[:prevent_update_suggestion], nil original_env, ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"] = ENV["RUBYGEMS_PREVENT_UPDATE_SUGGESTION"], nil original_disable, Gem.disable_system_update_message = Gem.disable_system_update_message, nil - Gem.configuration.last_update_check = 0 + Gem.configuration.last_update_check = 0 if reset_last_update_check Gem.ui.stub :tty?, tty do Gem.stub :rubygems_version, rubygems_version do @@ -69,6 +73,73 @@ class TestUpdateSuggestion < Gem::TestCase end end + def test_eglible_for_update_is_not_annoying_when_new_version_is_released + current_version = Gem::Version.new("1.2.0") + latest_version = current_version + + # checking for first time, it is not eglible since new version + # 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? + assert_equal Gem.configuration.last_update_check, @start_time + end + end + + # checking next week, it is not eglible since new version + # is not released yet and timestamp is stored + with_eglible_environment( + cmd: @cmd, + rubygems_version: current_version, + latest_rubygems_version: latest_version, + reset_last_update_check: false + ) do + Time.stub :now, @start_time + @week do + refute @cmd.eglible_for_update? + assert_equal Gem.configuration.last_update_check, @start_time + @week + end + end + + # pretend new version is released + latest_version = Gem::Version.new("1.3.0") + + # checking later same next week, it is not eglible even new version + # is released and timestamp is not stored + with_eglible_environment( + cmd: @cmd, + rubygems_version: current_version, + latest_rubygems_version: latest_version, + reset_last_update_check: false + ) do + Time.stub :now, @start_time + @week + @minute do + refute @cmd.eglible_for_update? + assert_equal Gem.configuration.last_update_check, @start_time + @week + end + end + end + + 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_equal Gem.configuration.last_update_check, @start_time + end + + # checking minute later is not eglible and not stored + Time.stub :now, @start_time + @minute do + refute @cmd.eglible_for_update? + assert_equal Gem.configuration.last_update_check, @start_time + end + + # checking week later is eglible again and stored + Time.stub :now, @start_time + @week do + assert @cmd.eglible_for_update? + assert_equal Gem.configuration.last_update_check, @start_time + @week + end + end + end + def test_eglible_for_update_prevent_config with_eglible_environment(cmd: @cmd) do begin @@ -121,7 +192,7 @@ class TestUpdateSuggestion < Gem::TestCase end def test_eglible_for_update_unwrittable_config - with_eglible_environment(ci: true, cmd: @cmd) do + with_eglible_environment(cmd: @cmd) do Gem.configuration.stub :state_file_writable?, false do refute @cmd.eglible_for_update? end |