我无法使用 Ruby 和 Rspec 将输出转换为 Json
I am unable to convert output to Json using Ruby and Rspec
我正在使用 https://regres.in 中的 public api,我已经尝试了几个示例,但仍然没有成功。
也不可能列出所有用户的正文,也不可能 return 用户名。
有人可以帮我吗?
my code:
module User
include HTTParty
base_uri 'https://regres.in'
format :json
end
describe 'grouping GET verb methods' do
it ' List all users' do
@users = User.get('/api/users?page=2')
puts expect(@users.code).to eq(200)
puts print @users // I had an error here
puts @users.code
end
it ' List one user' do
@user = User.get('/api/users/2')
expect(@user.code).to eq(200)
expect(@user['data']['id']).to eq(2) // I had an error here
expect(@user['data']['first_name']).to eq("Janet")
end
end
###### error ##############
Failure/Error: puts expect(@user['data']['id']).to eq(2)
JSON::ParserError:
809: unexpected token at '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><script type="text/javascript">var abp;</script><script type="text/javascript" src="http://ww17.regres.in/px.js?ch=1"></script><script type="text/javascript" src="http://w
w17.regres.in/px.js?ch=2"></script><script type="text/javascript">function handleABPDetect(){try{if(!abp) return;var imglog = document.createElement("img");imglog.style.height="0px";im
glog.style.width="0px";imglog.src="http://ww17.regres.in/sk-logabpstatus.php?a=YktuT09HMnIzSTVoNm1UZi9xanNYdEg2a0JMSmFVU2NoazdwTE84ZVMrdTZkQVd3N0o4YlFMQU9EQUY5WklxQlRpcGVuNVpaeUF2ZmZRZ
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/FYJR2.png
您确定这是基本 uri 吗?
谷歌搜索我发现了一个 public API ,其基本 uri 为“https://reqres.in”和“q”
我正在使用 https://regres.in 中的 public api,我已经尝试了几个示例,但仍然没有成功。 也不可能列出所有用户的正文,也不可能 return 用户名。 有人可以帮我吗?
my code:
module User
include HTTParty
base_uri 'https://regres.in'
format :json
end
describe 'grouping GET verb methods' do
it ' List all users' do
@users = User.get('/api/users?page=2')
puts expect(@users.code).to eq(200)
puts print @users // I had an error here
puts @users.code
end
it ' List one user' do
@user = User.get('/api/users/2')
expect(@user.code).to eq(200)
expect(@user['data']['id']).to eq(2) // I had an error here
expect(@user['data']['first_name']).to eq("Janet")
end
end
###### error ##############
Failure/Error: puts expect(@user['data']['id']).to eq(2)
JSON::ParserError:
809: unexpected token at '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><script type="text/javascript">var abp;</script><script type="text/javascript" src="http://ww17.regres.in/px.js?ch=1"></script><script type="text/javascript" src="http://w
w17.regres.in/px.js?ch=2"></script><script type="text/javascript">function handleABPDetect(){try{if(!abp) return;var imglog = document.createElement("img");imglog.style.height="0px";im
glog.style.width="0px";imglog.src="http://ww17.regres.in/sk-logabpstatus.php?a=YktuT09HMnIzSTVoNm1UZi9xanNYdEg2a0JMSmFVU2NoazdwTE84ZVMrdTZkQVd3N0o4YlFMQU9EQUY5WklxQlRpcGVuNVpaeUF2ZmZRZ
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/FYJR2.png
您确定这是基本 uri 吗? 谷歌搜索我发现了一个 public API ,其基本 uri 为“https://reqres.in”和“q”