grape api单元测试
来源:互联网 发布:2017年新出的网络剧 编辑:程序博客网 时间:2024/04/30 13:01
推荐两个网址:
https://github.com/rspec/rspec-rails
http://rspec.info/documentation/
上传了一个api的单元测试,https://github.com/shiralwz/grape_api_rspec
主要步骤:
(1)在Gemfile里加入新gem
gem 'rspec-rails', '~> 3.0'
(2)Download and install by running
bundle install
(3)Initialize the spec/
directory (where specs will reside) with
rails generate rspec:install
运行这个命令会自动生成以下三个文件
.rspec
spec/spec_helper.rb
spec/rails_helper.rb
(4)新增单元测试的代码
(5)执行
bundle exec rspec spec/...
============================
对api的单元测试代码
require 'rails_helper'RSpec.describe "helloAPI",type: :request do describe "GET the /api/hello" do it 'should return correct response via GET' do get '/api/hello', name: 'Mike' expect(response).to be_success expect(response).to have_http_status(200) body = JSON.parse(response.body) body['message'] == 'Hello Mike via GET' end end describe "POST the /api/hello" do it 'should return correct response via POST' do post '/api/hello', name: 'Mike' expect(response).to be_success expect(response).to have_http_status(200) //这里由于在api里设置了200所以检测200,默认是201 body = JSON.parse(response.body) body['message'] == 'Hello Mike via POST' end end end
0 0
- grape api单元测试
- grape API
- grape api参数为array
- Grape
- 如何使用 Grape-Swagger 生成 API 文档
- tyvj1617 grape
- Grape-demo1
- Web Api 的单元测试
- Grape 依赖管理器
- Spring Boot 单元测试-测试api
- Play pickup about grape planting
- rails grape 的使用详解
- rails grape最简单实例
- Struts2之Servlet API及单元测试初识
- 一个API接口的例子,包括单元测试
- Spring Boot构建RESTful API与单元测试
- Spring Boot构建RESTful API与单元测试
- 3 Hibernate:本地 API 单元测试优化
- 第4周 项目3-单链表应用(3)
- 第6周项目5-后缀表达式
- ArrayUtils工具类
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
- 第4周实践项目1-- 建立单链表
- grape api单元测试
- 第七周项目二~~链队算法库
- [原]iOS--字符编码,NSString和UTF-8间的转换
- Impala005-Impala SQL操作内部表和外部表
- xcode 7 错误:CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG
- 第8周 项目2—建立链串算法库
- asp jquery ajxs json和jsonp跨域请求
- AssetDatabaseOpenHelper 数据库工具类
- ant的讲解