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

Fix an error for Capybara/RSpec/HaveSelector when passing no arguments #129

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add `Capybara/AmbiguousClick` cop and make soft-deprecated `Capybara/ClickLinkOrButtonStyle` cop. If you want to use `EnforcedStyle: strict`, use `Capybara/AmbiguousClick` cop instead. ([@ydah])
- Add new `Capybara/FindAllFirst` cop. ([@ydah])
- Fix an error for `Capybara/RSpec/HaveSelector` when passing no arguments. ([@earlopain])

## 2.21.0 (2024-06-08)

Expand Down Expand Up @@ -78,6 +79,7 @@
[@aried3r]: https://github.com/aried3r
[@bquorning]: https://github.com/bquorning
[@darhazer]: https://github.com/Darhazer
[@earlopain]: https://github.com/earlopain
[@onumis]: https://github.com/onumis
[@oskarsezerins]: https://github.com/OskarsEzerins
[@pirj]: https://github.com/pirj
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/capybara/rspec/have_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class HaveSelector < ::RuboCop::Cop::Base
SELECTORS = %i[css xpath].freeze

def on_send(node)
argument = node.first_argument
return unless (argument = node.first_argument)

on_select_with_type(node, argument) if argument.sym_type?
on_select_without_type(node) if %i[str dstr].include?(argument.type)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/capybara/rspec/have_selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
RUBY
end

it 'registers no offense when no arguments are passed' do
expect_no_offenses(<<~RUBY)
expect(foo).to have_selector
RUBY
end

context 'when DefaultSelector is xpath' do
let(:default_selector) { 'xpath' }

Expand Down