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. #1045

Open
alyssais opened this issue Feb 22, 2018 · 4 comments · May be fixed by #1048
Open

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:

RSpec.configure { |c| c.extend self } if RSpec.respond_to?(:configure)

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 added a commit to alyssais/rspec-expectations that referenced this issue 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 rspec#1045.
@alyssais alyssais linked a pull request Mar 2, 2018 that will close this issue
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