source "https://rubygems.org" gem 'rest-client' gem 'rspec' gem 'json_expressions'
rafs-computer:rafael$ bundle Using diff-lcs 1.2.5 Using json_expressions 0.8.3 Using mime-types 2.3 Using netrc 0.7.7 Using rest-client 1.7.2 Using rspec-support 3.1.1 Using rspec-core 3.1.4 Using rspec-expectations 3.1.2 Using rspec-mocks 3.1.2 Using rspec 3.1.0 Using bundler 1.7.3 Your bundle is complete!
require 'rspec'
require 'rest_client'
describe 'GitHub API' do
it 'should return information about a user' do
result = RestClient.get 'https://api.github.com/users/rest-client', :content_type => :json, :accept => :json
expect(result.code).to eq(200)
end
end
{
"login": "rest-client",
"id": 2386701,
"avatar_url": "https://avatars.githubusercontent.com/u/2386701?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/rest-client",
"html_url": "https://github.com/rest-client",
"followers_url": "https://api.github.com/users/rest-client/followers",
"following_url": "https://api.github.com/users/rest-client/following{/other_user}",
"gists_url": "https://api.github.com/users/rest-client/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rest-client/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rest-client/subscriptions",
"organizations_url": "https://api.github.com/users/rest-client/orgs",
"repos_url": "https://api.github.com/users/rest-client/repos",
"events_url": "https://api.github.com/users/rest-client/events{/privacy}",
"received_events_url": "https://api.github.com/users/rest-client/received_events",
"type": "Organization",
"site_admin": false,
"name": "REST-Client Team",
"company": null,
"blog": "",
"location": null,
"email": null,
"hireable": false,
"bio": null,
"public_repos": 1,
"public_gists": 0,
"followers": 0,
"following": 0,
"created_at": "2012-09-20T15:01:43Z",
"updated_at": "2015-03-11T19:08:01Z"
}
require 'rspec'
require 'rest_client'
require 'json_expressions/rspec'
describe 'GitHub API' do
it 'should return 200 when asking information about a user' do
result = RestClient.get 'https://api.github.com/users/rest-client', :content_type => :json, :accept => :json
expect(result.code).to eq(200)
end
it 'should return proper data for a user' do
expected_data = JSON.parse(IO.read('users.json'))
result = RestClient.get 'https://api.github.com/users/rest-client', :content_type => :json, :accept => :json
expect(result).to match_json_expression(expected_data)
end
end
it 'should return proper data for a user' do
expected_data = JSON.parse(IO.read('users.json')) #解析users.json文件中的数据作为预期值
result = RestClient.get 'https://api.github.com/users/rest-client', :content_type => :json, :accept => :json
# expect(result).to match_json_expression(expected_data)
expected_data['updated_at'] = wildcard_matcher
end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有