Rspec错误:使用json格式创建操作的未知格式

时间:2013-10-23 03:54:32

标签: ruby-on-rails json rspec

创建方法

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响应的正确方法是什么?

0 个答案:

没有答案