Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround common options mutation in Gem::Command test #2098

Merged
merged 1 commit into from Nov 25, 2017
Merged

Workaround common options mutation in Gem::Command test #2098

merged 1 commit into from Nov 25, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 24, 2017

We need to restore common options if we want to execute commands using
such options in other tests. For example, if a test runs a command with
--silent option, we get this kind of error:

OptionParser::InvalidOption: invalid option: --silent

  We need to restore common options if we want to execute commands using
such options in other tests. For example, if a test runs a command with
`--silent' option, we get this kind of error:

    OptionParser::InvalidOption: invalid option: --silent
@ghost
Copy link
Author

ghost commented Nov 24, 2017

Description:

Workaround common options mutation in Gem::Command test. My use case
was writing tests for Gem::Commands::SetupCommand#execute. But this
code also executes the Gem::Commands::PristineCommand using
--silent option, which don't exist anymore if it's removed in
Gem::Command test.

Tasks:

  • Write tests

No test since it's a change in the test suite only. So I don't think
it's necessary.

  • Write code to solve the problem
  • Get code review from coworkers / friends

I hope my "workaround" is acceptable, but would be happy to try
another way if needed, please let me know.

@segiddins
Copy link
Member

Why is this necessary, given that we always correctly set the common options in setup?

@ghost
Copy link
Author

ghost commented Nov 24, 2017 via email

@ghost
Copy link
Author

ghost commented Nov 25, 2017

Sorry for previous comment formatting, I tried to follow "github
markdown", but seems ignored when replying by mail. Here is the
main example again:

# test/test_gem_command_common_options.rb
require 'rubygems/test_case'
require 'rubygems/command'

class TestGemCommandCommonOptions < Gem::TestCase
  def test_common_options
    opts = Gem::Command.common_options.map { |options| options[0][0] }
    assert_includes opts, '-h'
  end
end
$ ruby -w -Ilib:test:bundler/lib --disable-gems \
  -e 'require "rubygems"; require "minitest/autorun"' \
  -e 'require "test_gem_command_common_options"'
.
1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
$ ruby -w -Ilib:test:bundler/lib --disable-gems \
  -e 'require "rubygems"; require "minitest/autorun"' \
  -e 'require "test_gem_command_common_options"' \
  -e 'require "rubygems/test_gem_command"'
...............F
  1) Failure:
TestGemCommandCommonOptions#test_common_options […/test_gem_command_common_options.rb:7]:
Expected ["-x"] to include "-h".
zsh: exit 1

The first run shows that the example test
TestGemCommandCommonOptions passes when run in isolation.
The second run includes TestGemCommand and shows that it modifies
behavior globally, which affects other test cases.

@segiddins
Copy link
Member

Cool, thanks for the explanation!
@bundlerbot r+

@bundlerbot
Copy link
Collaborator

📌 Commit a1336fa has been approved by segiddins

@bundlerbot
Copy link
Collaborator

⌛ Testing commit a1336fa with merge 4a04596...

bundlerbot added a commit that referenced this pull request Nov 25, 2017
…karound, r=segiddins

Workaround common options mutation in Gem::Command test

  We need to restore common options if we want to execute commands using
such options in other tests. For example, if a test runs a command with
`--silent` option, we get this kind of error:

    OptionParser::InvalidOption: invalid option: --silent
@bundlerbot
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: segiddins
Pushing 4a04596 to master...

@bundlerbot bundlerbot merged commit a1336fa into rubygems:master Nov 25, 2017
@ghost ghost deleted the test-command-common_options-mutation_workaround branch November 27, 2017 01:50
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.

None yet

3 participants