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

Add Bundler.with_unbundled_env to RSpec.shared_context 'isolated environment' #12612

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexWayfer
Copy link
Contributor

It's more correct. And without it there are errors, like about yard gem:

> bundle exec rspec

...
/home/alex/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/definition.rb:570:in `materialize': Could not find yard-0.9.34 in locally installed gems (Bundler::GemNotFound)
	from /home/alex/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/definition.rb:203:in `specs'
	from /home/alex/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/definition.rb:270:in `specs_for'
...

There are some incompatibilities, but they can be resolved.


Basically, I couldn't run specs from "the cold start".


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

…nvironment'`

It's more correct. And without it there are errors, like about `yard` gem:

```
> bundle exec rspec

...
/home/alex/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/definition.rb:570:in `materialize': Could not find yard-0.9.34 in locally installed gems (Bundler::GemNotFound)
	from /home/alex/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/definition.rb:203:in `specs'
	from /home/alex/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/definition.rb:270:in `specs_for'
...
```

There are some incompatibilities, but they can be resolved.
create_empty_file('Gemfile')
create_empty_file('Gemfile.lock')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this CLI returns "can't open file Gemfile.lock", I don't know why.

before do
# Makes sure the project dir of rubocop server is the isolated_environment
create_empty_file('Gemfile')
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to move create_empty_file('Gemfile') into "isolated environment", but it breaks more than helps.

@AlexWayfer
Copy link
Contributor Author

Please, help me with this, I don't understand:

> bundle exec rspec spec/rubocop/cli/auto_gen_config_spec.rb

Randomized with seed 43534
...................F.F...........................

Failures:

  1) RuboCop::CLI --auto-gen-config --auto-gen-config when .rubocop.yml contains a single line inherit_from in an ERB conditional overwrites an existing todo file
     Got 3 failures from failure aggregation block.
     Shared Example Group: "overwrites todo file" called from ./spec/rubocop/cli/auto_gen_config_spec.rb:352
     # ./spec/support/cli_spec_behavior.rb:26:in `block (2 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:46:in `block (2 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (5 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:8:in `block (3 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in <top (required)>'

     1.1) Failure/Error:
            expect(File.readlines('.rubocop_todo.yml')[8..].map(&:chomp))
              .to eq(['# Offense count: 1',
                      '# This cop supports safe autocorrection (--autocorrect).',
                      '# Configuration parameters: AllowForAlignment, ' \
                      'EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals.',
                      '# SupportedStylesForExponentOperator: space, no_space',
                      '# SupportedStylesForRationalLiterals: space, no_space',
                      'Layout/SpaceAroundOperators:',
                      '  Exclude:',
                      "    - 'example1.rb'",
          
            expected: ["# Offense count: 1", "# This cop supports safe autocorrection (--autocorrect).", "# Configuration p...reCopDirectives, AllowedPatterns.", "# URISchemes: http, https", "Layout/LineLength:", "  Max: 125"]
                 got: ["# Offense count: 1", "# This cop supports safe autocorrection (--autocorrect).", "# Configuration p...reCopDirectives, AllowedPatterns.", "# URISchemes: http, https", "Layout/LineLength:", "  Max: 125"]
          
            (compared using ==)
          # ./spec/rubocop/cli/auto_gen_config_spec.rb:309:in `block (5 levels) in <top (required)>'

     1.2) Failure/Error: expect(File.readlines('.rubocop.yml').map(&:chomp)).to eq(code)
          
            expected: ["<% if ENV[\"HZPKCEAXTFQLOWB\"] %>", "inherit_from: .rubocop_todo.yml", "<% end %>"]
                 got: ["<% if ENV[\"HZPKCEAXTFQLOWB\"] %>", "inherit_from: .rubocop_todo.yml", "", "<% end %>"]
          
            (compared using ==)
          # ./spec/rubocop/cli/auto_gen_config_spec.rb:335:in `block (5 levels) in <top (required)>'

     1.3) Failure/Error: expect(new_cli.run(['example1.rb'])).to eq(0)
          
            expected: 0
                 got: 1
          
            (compared using ==)
          # ./spec/rubocop/cli/auto_gen_config_spec.rb:340:in `block (5 levels) in <top (required)>'

  2) RuboCop::CLI --auto-gen-config --auto-gen-config when .rubocop.yml contains a multiline inherit_from in an ERB conditional overwrites an existing todo file
     Got 3 failures from failure aggregation block.
     Shared Example Group: "overwrites todo file" called from ./spec/rubocop/cli/auto_gen_config_spec.rb:358
     # ./spec/support/cli_spec_behavior.rb:26:in `block (2 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:46:in `block (2 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (5 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `chdir'
     # ./lib/rubocop/rspec/shared_contexts.rb:30:in `block (4 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:8:in `block (3 levels) in <top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:7:in `block (2 levels) in <top (required)>'

     2.1) Failure/Error:
            expect(File.readlines('.rubocop_todo.yml')[8..].map(&:chomp))
              .to eq(['# Offense count: 1',
                      '# This cop supports safe autocorrection (--autocorrect).',
                      '# Configuration parameters: AllowForAlignment, ' \
                      'EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals.',
                      '# SupportedStylesForExponentOperator: space, no_space',
                      '# SupportedStylesForRationalLiterals: space, no_space',
                      'Layout/SpaceAroundOperators:',
                      '  Exclude:',
                      "    - 'example1.rb'",
          
            expected: ["# Offense count: 1", "# This cop supports safe autocorrection (--autocorrect).", "# Configuration p...reCopDirectives, AllowedPatterns.", "# URISchemes: http, https", "Layout/LineLength:", "  Max: 125"]
                 got: ["# Offense count: 1", "# This cop supports safe autocorrection (--autocorrect).", "# Configuration p...reCopDirectives, AllowedPatterns.", "# URISchemes: http, https", "Layout/LineLength:", "  Max: 125"]
          
            (compared using ==)
          # ./spec/rubocop/cli/auto_gen_config_spec.rb:309:in `block (5 levels) in <top (required)>'

     2.2) Failure/Error: expect(File.readlines('.rubocop.yml').map(&:chomp)).to eq(code)
          
            expected: ["<% if ENV[\"HZPKCEAXTFQLOWB\"] %>", "inherit_from:", "  - .rubocop_todo.yml", "  - other.yml", "<% end %>"]
                 got: ["<% if ENV[\"HZPKCEAXTFQLOWB\"] %>", "inherit_from: .rubocop_todo.yml", "", "<% end %>"]
          
            (compared using ==)
          # ./spec/rubocop/cli/auto_gen_config_spec.rb:335:in `block (5 levels) in <top (required)>'

     2.3) Failure/Error: expect(new_cli.run(['example1.rb'])).to eq(0)
          
            expected: 0
                 got: 1
          
            (compared using ==)
          # ./spec/rubocop/cli/auto_gen_config_spec.rb:340:in `block (5 levels) in <top (required)>'

Finished in 6.22 seconds (files took 1.29 seconds to load)
49 examples, 2 failures

Failed examples:

rspec ./spec/rubocop/cli/auto_gen_config_spec.rb[1:1:11:1] # RuboCop::CLI --auto-gen-config --auto-gen-config when .rubocop.yml contains a single line inherit_from in an ERB conditional overwrites an existing todo file
rspec ./spec/rubocop/cli/auto_gen_config_spec.rb[1:1:12:1] # RuboCop::CLI --auto-gen-config --auto-gen-config when .rubocop.yml contains a multiline inherit_from in an ERB conditional overwrites an existing todo file

Randomized with seed 43534

@AlexWayfer
Copy link
Contributor Author

And I see fails from spec/rubocop/cli/options_spec.rb in CI, but can't reproduce them.

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

1 participant