When I try to use new matcher, I'm getting You must pass an argument rather than a block to use the provided matcher (have enqueued job), or the matcher must implement supports_block_expectations?
error.
After debugging it turns out that it's not autoloaded, I have to include RSpec::Rails::Matchers.
Any idea why is that?
If there's no have_foo_bar matcher defined, rspec-matchers' dynamic matcher support and have_foo_bar is treated as a matcher that delegates to has_foo_bar?. That's why you're getting the error that you got.
As for having to include RSpec::Rails::Matchers....that's the module in which you defined have_enqueued_job:
https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/matchers/active_job.rb
That module isn't included automatically in all RSpec example groups. Although, perhaps it should. There are a lot of other matchers in that module that, IMO, should be usable in any context. @cupakromer, WDYT?
yes, I think it should be available out of the box in case when AJ is available, I thought that this is enough https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/matchers.rb#L22-L24 but it's not
I got tripped up by this same thing. I needed to include RSpec::Rails::Matchers in a class where I'd moved some code, even though the controller was automatically ready to use the have_enqueued_job matcher. I think it'd also be nice if the module were included by default.
Thanks for the explanation! It allowed me to get on my way.
I just ran into this as well. It seems like either these matchers should be included by default or the docs should include the necessary set up to avoid similar confusion. Happy to help with either.
Bump. Running into this as well.
That module isn't included automatically in all RSpec example groups. Although, perhaps it should.
I think it should be automatically included in all example groups. Jobs can come out of anywhere, and any :type => . It's confusing right now.
@soulcutter It is automatically included, just only in Rails example groups, so lib code etc won't trigger it, PR incoming to fix this though
Most helpful comment
@soulcutter It is automatically included, just only in Rails example groups, so lib code etc won't trigger it, PR incoming to fix this though