Skip to content

Conversation

@pirj
Copy link
Member

@pirj pirj commented Jul 8, 2022

RSpec 4 will eventually be released. Since we're checking RSpec style, why don't we use RSpec 4 at least in an optional job to help test it out?

Below what had to be done.

Move dev dependencies to Gemfile

A similar (unmerged) rspec-support PR rspec/rspec-support#517

Reasoning (https://bundler.io/v2.2/man/gemfile.5.html#GEMSPEC):

The .gemspec file is ... where you specify the dependencies your gem needs to run.

Even though it contradicts the very existence of add_development_dependency.

Discussions on this topic:

Refactored our CI workflow

Extracted edge RuboCop in separate job(s).

RSpec 4

It's complicated and not an obvious situation with shared contexts.
Previously, they were auto-included using matching metadata. Now, only explicitly (see changes to the spec/spec_helper.rb). This revealed two issues:

  1. Those shared examples that define metadata themselves, e.g. shared_examples 'config', :config do would be included first. Since we're overriding the one defined in rubocop with ours, to set other_cops with a proper RSpec DSL configuration, there is only one way of doing that in a non-Yoda order as we have to do now:
  config.include_context 'with default RSpec/Language config', :config # Intuituvely, this should go below
  config.include_context 'config', :config

is to remove :config from the definition in rubocop.
But this makes it complicated, since well-known extensions depend on this metadata, and custom cops' specs, too.
This needs to be somehow fixed on RSpec 4 side.

  1. There is no straightforward way now to define a satellite example group for specs, like e.g. 'smoke test' one. There is no such thing as config.include_examples. However, config.include_context exists, and it's an alias that has different semantics but identical behaviour.

A similar (unmerged) `rspec-support` PR rspec/rspec-support#517

Reasoning (https://bundler.io/v2.2/man/gemfile.5.html#GEMSPEC):

> The .gemspec file is ... where you specify the dependencies your gem needs *to run*.

Even though it contradicts the very existence of add_development_dependency.

Discussions:
 - ruby/rubygems#5065
 - ruby/rubygems#1104
@pirj pirj self-assigned this Jul 8, 2022
@pirj pirj requested review from Darhazer and bquorning July 8, 2022 09:10
@pirj

This comment was marked as resolved.

@pirj pirj marked this pull request as draft July 8, 2022 10:30
@pirj pirj force-pushed the use-edge-rspec-for-development branch 7 times, most recently from 3b1d588 to 76bbe70 Compare July 10, 2022 01:32
pirj added 2 commits July 10, 2022 04:37
Starting from RSpec 4, the implicit shared context inclusion, when a
shared context would have been included to an example if the example has
matching metadata, is not the case anymore.

See:
 - rspec/rspec-core#2834
 - rspec/rspec-core#2832
 - rspec/rspec-core#2878
@pirj pirj marked this pull request as ready for review July 10, 2022 01:38
@pirj pirj force-pushed the use-edge-rspec-for-development branch from 76bbe70 to c92d184 Compare July 10, 2022 01:38
RSpec 4 will eventually be released. Since we're checking its style, why
don't we add a job to use it to run our specs.
This will help a bit to test RSpec 4 out.
@pirj pirj force-pushed the use-edge-rspec-for-development branch from c92d184 to a004d11 Compare July 10, 2022 01:55

it_behaves_like :something
it_should_behave_like :something
it_should_behave_like :something if RSpec::Core::Version::STRING < '4.0'
Copy link
Member Author

Choose a reason for hiding this comment

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

As we not only parse those weird specs, but also actually run them with rake spec, we have to conditionally call it_should_behave_like as this alias has been removed from RSpec 4.

@pirj pirj requested a review from bquorning July 10, 2022 01:57
@pirj pirj changed the title Use RSpec 4 pre-release Add an RSpec 4 pre-release CI job Jul 10, 2022
Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

Fine by me.

Perhaps add a link to the RSpec 4 changelogs?

@pirj
Copy link
Member Author

pirj commented Jul 11, 2022

add a link to the RSpec 4 changelogs?

@bquorning Do you mean in code comments somewhere? I've added them to the commit message.

@@ -1,3 +1,2 @@
--require spec_helper
--color
Copy link
Member Author

@pirj pirj Jul 11, 2022

Choose a reason for hiding this comment

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

Comment on lines -27 to -28
config.filter_run focus: true
config.run_all_when_everything_filtered = true
Copy link
Member Author

Choose a reason for hiding this comment

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

config.run_all_when_everything_filtered = true

# Forbid RSpec from monkey patching any of our objects
config.disable_monkey_patching!
Copy link
Member Author

Choose a reason for hiding this comment

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

config.include(ExpectOffense)

config.include_context 'with default RSpec/Language config', :config
config.include_context 'config', :config
Copy link
Member Author

@pirj pirj Jul 11, 2022

Choose a reason for hiding this comment

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

After this PR is merged (and released, and we bump our rubocop dependency, and we remove the :config from our 'with default RSpec/Language config' shared context), this line becomes redundant.

@pirj pirj merged commit 858ba95 into master Jul 11, 2022
@pirj pirj deleted the use-edge-rspec-for-development branch July 11, 2022 23:33
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.

4 participants