1

创建方法

def create
  @user = User.new(user_params) 
  if @user.save
    respond_with("User #{@user.id}.", code: 200)
  else
    respond_with("User creation failed #{@user.errors}", code: 500)
  end
end

我的规格:

describe "POST 'create'" do
  context "with valid parameters" do
    let(:credentials) { { :email => "new_user@example.net", :company_id => 1 } }
  it "creates a new user" do
    expect { post :create, :user => credentials }.to change(User, :count).by(1)
  end

给出错误:Unknown format

当代码更改为expect { post :create, :user => credentials, :format => json }.to change(User, :count).by(1)错误时:

undefined local variable or method `json'

指定 json 响应的正确方法是什么?

4

0 回答 0