Skip to content

Conversation

@pvdb
Copy link
Contributor

@pvdb pvdb commented Nov 11, 2024

It is very unclear why the Rake::TestCase#rake_system_dir helper method:

  def rake_system_dir
    @system_dir = "system"

    FileUtils.mkdir_p @system_dir

    File.write File.join(@system_dir, "sys1.rake"), <<~SYS
      task "sys1" do
        puts "SYS1"
      end
    SYS

    ENV["RAKE_SYSTEM"] = @system_dir
  end

... creates and sets a @system_dir instance variable. 🤔

On inspection, it turns out its only use is the following assertion in one of the test cases:

    assert_equal @system_dir, @app.system_dir

... so this PR removes the ivar and hardcodes the expected "system" value in the assertion:

-    assert_equal @system_dir, @app.system_dir
+    assert_equal "system", @app.system_dir

This may seem a tad controversial, but as it turns out, the sys1.rake Rakefile name and the SYS1 Rakefile contents (also "private" - as it were - to that very same utility method) are already hardcoded in one of the Rake test cases:

$ git grep -i sys1 -- 'test/test*'
test/test_rake_functional.rb:    rake "-g", "sys1"
test/test_rake_functional.rb:    assert_match %r{^SYS1}, @out
test/test_rake_functional.rb:    rake "-g", "sys1", "-T", "extra"
test/test_rake_functional.rb:    rake "sys1", "--trace"
test/test_rake_functional.rb:    assert_match %r{^SYS1}, @out
test/test_rake_functional.rb:    rake "-G", "sys1"
test/test_rake_functional.rb:    rake "--nosearch", "sys1"
test/test_rake_functional.rb:    assert_match %r{^SYS1}, @out
$ _

... so the change in this PR just makes things more consistent with the other test cases and assertions.

@pvdb pvdb changed the title chore: refactor "exposed" @system_dir instance variable (in helper method) refactor: remove "exposed" @system_dir instance variable (in helper method) Dec 8, 2024
@hsbt
Copy link
Member

hsbt commented Dec 9, 2024

👍

@hsbt hsbt merged commit 2e9a25b into ruby:master Dec 9, 2024
28 checks passed
@pvdb pvdb deleted the system_dir_ivar branch December 9, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants