Ruby on rails Rails集成测试失败,因为当前路径的最后一个斜杠

Ruby on rails Rails集成测试失败,因为当前路径的最后一个斜杠,ruby-on-rails,capybara,integration-testing,Ruby On Rails,Capybara,Integration Testing,我正在用capybara编写一个集成测试,这里是我测试的代码 test "when providing invalid data" do admin = create(:administrator) signin_administrator_as admin.email, admin.password visit new_admin_country_path click_button t("buttons.admin.save") assert_eq

我正在用capybara编写一个集成测试,这里是我测试的代码

test "when providing invalid data" do
    admin = create(:administrator)
    signin_administrator_as admin.email, admin.password

    visit new_admin_country_path

    click_button t("buttons.admin.save")

    assert_equal admin_countries_path, current_path
    assert page.has_text? t("admin.form_error_message")
end
在控制器中

def create
  @country = Country.new(country_params)

  if @country.save
    redirect_to admin_countries_path, notice: t("flash.admin.country.create.notice")
  else
    render :new
  end
end
我的表单中有一个用于插入和更新的分部

<%= form_for @country, url: admin_country_path(@country) do |f| %>
  <p>
    <%= f.label :code, t("labels.country.code") %>
    <%= f.text_field :code %>
  </p>

  <p>
    <%= f.label :portuguese_name, t("labels.country.portuguese_name") %>
    <%= f.text_field :portuguese_name %>
  </p>

  <p>
    <%= f.label :spanish_name, t("labels.country.spanish_name") %>
    <%= f.text_field :spanish_name %>
  </p>

  <p>
    <%= f.label :english_name, t("labels.country.english_name") %>
    <%= f.text_field :english_name %>
  </p>

  <%= f.submit t("buttons.admin.save") %>
<% end %>
这是我的路线定义

namespace :admin do
    root to: "signin#new"

    get "/signin", to: "signin#new"
    post "/signin", to: "signin#create"

    get "/dashboard", to: "dashboard#index"

    resources :countries
end
有人能帮我吗


谢谢。

问题在于,您的表单使用的路由指向显示页面,而不是指向
POST/admin/countries
端点


您有两种选择:将url更改为
admin\u countries\u path
,或仅使用
简化路由;
:admin
引用端点,因此Rails可以正确推断资源的整个路由。

请显示路由设置。
namespace :admin do
    root to: "signin#new"

    get "/signin", to: "signin#new"
    post "/signin", to: "signin#create"

    get "/dashboard", to: "dashboard#index"

    resources :countries
end