失败/错误:获取:显示,ID: @user.id,格式:: JSON



我正在尝试测试此控制器,但错误正在返回。

class Api::V1::UsersController < ApplicationController
  respond_to :json
  def show
    respond_with User.find(params[:id])
  end
end
require 'rails_helper'
RSpec.describe Api::V1::UsersController, type: :controller do
  before(:each) { request.headers['Accept'] = "application/vnd.marketplace.v1" }
  describe "GET #show" do
    before(:each) do
      @user = FactoryBot.create :user
      get :show, :id => @user.id, format: :json
    end
    it "returns the information about a reporter on a hash" do
      user_response = JSON.parse(response.body, symbolize_names: true)
      expect(user_response[:email]).to eql @user.email
    end
    it { should respond_with 200 }
  end
end

Bundle Exec RSPEC Spec/Controllers/api/v1/users_controller_spec.rb

失败:

1(api :: v1 ::用户controller get #show返回有关哈希的记者的信息 失败/错误:获取:显示,:id => @user.id,格式:: JSON

 ArgumentError:
   unknown keyword: id
 # ./spec/controllers/api/v1/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

2(api :: v1 ::用户controller获取#show 失败/错误:获取:显示,:id => @user.id,格式:: JSON

 ArgumentError:
   unknown keyword: id
 # ./spec/controllers/api/v1/users_controller_spec.rb:9:in `block (3 levels) in <top (required)>'

在0.05594秒内完成(文件花费2.35秒的加载(2个例子,2个失败

失败的示例:

rspec ./spec/controllers/api/v1/users_controller_spec.rb:12#api :: v1 :: v1 :: Userscontroller get #show #show返回有关Hash上的记者的信息rspec ./spec/controllers/api/v1/users_controller_spec.rb:17#api :: v1 :: usercontroller get #show #show

您应该通过params HASH包含您有兴趣提交的参数:

get :show, params: { id: @user.id }

最新更新