Skip to content

Commit

Permalink
Fix an error for Capybara/RSpec/HaveSelector when passing no argume…
Browse files Browse the repository at this point in the history
…nts.
  • Loading branch information
Earlopain committed Aug 19, 2024
1 parent f501b34 commit 29e9753
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit 29e9753

Please sign in to comment.