简体   繁体   中英

RSpec Argument Error invalid keys :method, :action

Is anyone able to shed light on why this error:

 Failure/Error:
   expect(render).to have_selector('form', method: 'post', action: 'index') do |form|
     expect(form).to have_selector('input', type: 'submit')

 ArgumentError:
   invalid keys :method, :action, should be one of :count, :minimum, :maximum, :between, :text, :visible, :exact, :match, :wait

is generated on this code:

require 'rails_helper'

describe "messages/new.html.erb" do
  it "renders a form to create a message" do
    assign(:message, mock_model('Message'))
    render
    expect(render).to have_selector('form',
      method: 'post',
      action: 'index'
    ) do |form|
      expect(form).to have_selector('input', type: 'submit')
    end
  end
end

Much thanks.

Your call to have_selector isn't right: you can't check for the presence of attributes on elements in that way. You can however include this in the selector, eg

have_selector("form[method=post][action=index]")

If the rendered html actually has the full path or url for the form then you need to use the routing helpers to generate that url and use it in the selector.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM