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

Matcher DSL isn't available inside example groups if rspec-expectations is loaded before rspec-core. #122

Open
alyssais opened this issue Feb 22, 2018 · 4 comments

Comments

@alyssais
Copy link
Contributor

Not sure if this is the right place to report this, but it seemed the most sensible.

The rspec-expectations matcher DSL checks at load time whether RSpec.configuration is defined, and only includes itself if it is:

https://github.com/rspec/rspec-expectations/blob/a81b0678bd504c10da5475d73a676f6f60c1e9d7/lib/rspec/matchers/dsl.rb#L97

This causes problems if, e.g., you have a Gemfile like this:

source "https://rubygems.org"
gem "rspec-rails"
gem "rspec-collection_matchers"

When rspec-collection_matchers is loaded, it loads rspec-expectations, but rspec-core has not yet been loaded. This means that the matcher DSL will not be available in example groups, and so scoped aliased and negated matchers cannot be used without manually extending RSpec::Matchers::DSL.

@JonRowe
Copy link
Member

JonRowe commented Feb 22, 2018

This generally shouldn't be an issue, after all the first thing require 'rspec/rails does is to load rspec/core, theres not really a nice way to delay this check other than to say that its a requirement to include rspec-core first. Although maybe we could perform the check in rspec core too and load it that way, WDYT @myronmarston

@myronmarston
Copy link
Member

WFYT @myronmarston

I have no idea what WFYT stands for...

Anyhow, IMO it's an anti pattern that rspec-expectations has knowledge of how to hook itself into rspec-core. Instead, we should change rspec-core to do that. Want to work up a PR to fix it, @alyssais ?

@JonRowe
Copy link
Member

JonRowe commented Feb 22, 2018

WFYT was WDYT typo'd :)

Anyhow, IMO it's an anti pattern that rspec-expectations has knowledge of how to hook itself into rspec-core. Instead, we should change rspec-core to do that.

Yep I agree

@alyssais
Copy link
Contributor Author

Want to work up a PR to fix it, @alyssais ?

Will see if I have time at the weekend :)

alyssais referenced this issue in alyssais/rspec-expectations Mar 2, 2018
rspec-expectations shouldn't have knowledge of how to hook itself into
rspec-core. rspec-core already includes the `RSpec::Matchers` module in
example groups, so just including the module there (in addition to
extending it) is enough to provide it to rspec-core, even if rspec-core
hasn't been loaded yet and is loaded after rspec-expectations.

Fixes https://github.com/rspec/rspec-expectations/issues/1045.
@JonRowe JonRowe closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2024
@JonRowe JonRowe reopened this Nov 27, 2024
@JonRowe JonRowe transferred this issue from rspec/rspec-expectations Nov 30, 2024
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 a pull request may close this issue.

3 participants