AlbertMunichMar
AlbertMunichMar

Reputation: 1866

Rails project, while testing with capybara: ArgumentError: Unused parameters passed to Capybara::Queries::SelectorQuery : [4]

Test that the form has 4 inputs is not working, I am copy pasting the line from the documentation:

assert_select "form input", 4

any ideas?

require "application_system_test_case"

class QuestionsTest < ApplicationSystemTestCase
  test "visiting /ask renders the form" do
    visit ask_url

    assert_selector "p", text: "Ask your coach anything"

    assert_select "form input", 4
  end
end

The complete error message is:

Error:
QuestionsTest#test_visiting_/ask_renders_the_form:
ArgumentError: Unused parameters passed to Capybara::Queries::SelectorQuery : [4]
    test/system/questions_test.rb:9:in `block in <class:QuestionsTest>'

Any help would be appreciate.

Don't know why my question is wrong according to stackoverflow, after having read their guidelines.

Upvotes: 2

Views: 475

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

The assert_select method you're copying from documentation is a Rails method that was moved out of Rails into the rails-dom-testing gem around Rails 4.2. However, the assert_select method you're actually calling is a Capybara provided method - https://www.rubydoc.info/gems/capybara/Capybara/Minitest/Assertions#assert_select-instance_method - which deals with <select> elements, doesn't take the same parameters, and isn't the correct method for what you are trying to do. With Capybara what you are trying to do is

assert_css "form input", count: 4

which is the same as assert_selector :css, "form input", count: 4, which can also be written assert_selector "form input", count: 4 if Capybara.default_selector == :css.

Upvotes: 4

Related Questions