【发布时间】:2016-07-24 06:17:21
【问题描述】:
我正在尝试在 rspec 中测试用 rails 编写的 json。我不确定语法。这是我目前所拥有的:
require 'rails_helper'
RSpec.describe V1::VersionsController, :type => :controller do
before do
@token = "0"
request.env["Content-Type"] = 'application/vnd.api+json; charset=utf-8'
end
describe "GET index" do
it "renders the index JSON" do
@request.headers['Content-Type'] = 'application/vnd.api+json; charset=utf-8'
request.env['Content-Type'] = 'application/vnd.api+json; charset=utf-8'
params = { token: @token }
get :index, :format => :json, token: @token
#response.should be_success
body = JSON.parse(response.body)
ap body
end
end
end
如您所见,我以多种不同的方式进行了尝试。但我收到 403 错误。
我正在使用Rails 5.0.0.beta3、ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] 和rspec-3.1。
【问题讨论】:
-
我们可以查看您的控制器代码及其用于验证请求的方法吗?
标签: ruby-on-rails ruby json rspec json-api