由于参数错误,轨道测试失败:参数数量错误(1 表示 2)



我想我可能患有隧道视觉,因为我在我的评论之后看不到第 22 行还需要什么其他参数。

    require 'test_helper'
    class RecipesControllerTest < ActionController::TestCase
      setup do
        @recipe = recipes(:one)
        login_as(:one)
      end
      test "should get index" do
        get :index
        assert_response :success
        assert_not_nil assigns(:recipes)
      end
      test "should get new" do
        get :new
        assert_response :success
      end
      test "should create recipe" do
        # it's complaining about this test
        test "should show recipe" do
          get :show, id: @recipe, user_id: @recipe.user_id
          assert_response :success
        end
        test "should get edit" do
          get :edit, id: @recipe
          assert_response :success
        end
        test "should update recipe" do
          patch :update, id: @recipe, recipe: { image_url: @recipe.image_url, instructions: @recipe.instructions, title: @recipe.title, user_id: @recipe.user_id }
          assert_redirected_to recipe_path(assigns(:recipe))
        end
        test "should destroy recipe" do
          assert_difference('Recipe.count', -1) do
            delete :destroy, id: @recipe, user_id: @recipe.user_id
          end
          assert_redirected_to recipes_path
        end
      end
    end

我认为 show 方法只需要 id 即可找到食谱。我试过包括

user_id: @recipe.user_id

但我仍然得到相同的 1 个参数用于 2 条错误消息。

请注意:这是我的第一个 Rails 项目之一,也就是我在这里的极端菜鸟。我欢迎对你所看到的任何事情提出所有建设性的批评。谢谢!

为什么测试块内有一个测试块?

test "should create recipe" do
  # it's complaining about this test
  test "should show recipe" do

移除外部test "should create recipe" do并将其添加到与test "should show recipe" do相同的级别

相关内容

最新更新