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

NoMethodError: undefined method `matcher' for class RSpec::ExampleGroups... #12

Open
sergiobayona opened this issue Jul 31, 2024 · 2 comments

Comments

@sergiobayona
Copy link

require 'rails_helper'

RSpec.describe Projects::NewProjectLinkComponent, type: :component do
  let(:company) { create(:company) }

  let(:kwargs) { { company: company } }

  it { is_expected.to inherit_from ApplicationComponent }

end

Running this raises:

NoMethodError:
  undefined method `matcher' for class RSpec::ExampleGroups::ProjectsNewProjectLinkComponent
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:752:in `method_missing'
# /Users/sergiobayona/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/rspec-viewcomponent-0.1.0/lib/rspec/viewcomponent/context.rb:26:in `block (2 levels) in <module:Context>'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-support-3.12.1/lib/rspec/support/with_keywords_when_needed.rb:22:in `class_exec'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-support-3.12.1/lib/rspec/support/with_keywords_when_needed.rb:22:in `class_exec'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-core-3.12.2/lib/rspec/core/shared_example_group.rb:38:in `block in include_in'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:822:in `with_frame'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-core-3.12.2/lib/rspec/core/shared_example_group.rb:37:in `include_in'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:386:in `find_and_eval_shared'
# /Users/sergiobayona/.gem/ruby/3.3.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:344:in `include_context'
# /Users/sergiobayona/.rbenv/versions/3.3.2/lib/ruby/gems/3.3.0/gems/rspec-viewcomponent-0.1.0/lib/rspec/viewcomponent/context.rb:33:in `block in <module:Context>'
@sergiobayona
Copy link
Author

matcher definition at https://github.com/ViewComponent/rspec-viewcomponent/blob/main/lib/rspec/viewcomponent/context.rb#L26-L30

should be:

RSpec::Matchers.define :be_rendered do |expected|
  match do |actual|
    expect(actual).to be_render
  end
end

instead of:

  matcher :be_rendered do
    match do |actual|
      expect(actual).to be_render
    end
  end

no? or is it an rspec version issue?

Thanks.

@boardfish
Copy link
Collaborator

boardfish commented Aug 1, 2024

Hey @sergiobayona, thanks for raising this! This is really interesting – I think it might be environment-dependent, because a much larger repo I work on similarly doesn't let you define matchers in this way and I'm not sure why 🤔 Could you try and get a reduced test case so that I can understand how exactly it's failing?

In the meantime, if we can't figure out the root cause, then I'd be happy to update this gem to support that.

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

No branches or pull requests

2 participants