In the test,  we should use the ‘describe’,  ‘context’, ‘it’ structure.

Here I use a controller test as an example.

I have this my_controller.rb with two controller actions:

class MyController < ApplicationControllerdef controller_action_1# Code goes hereenddef controller_action_2# Code goes hereend
end

And controller test file my_controller_test.rb:

require ‘test_helper’class MyControllerTest < ActionController::TestCase# Initialize the variables that will be used in all describe block tests within MyControllerTest classbefore dov_block = ‘this variable is only accessible in this block’@v_describe_level = ‘this varible is accessible in all describe blocks’end# Test for controller action 1describe ‘#controller_action_1′ do# Intialize the variables that will be used in all context block tests within this describe blockbefore dov_block = ‘this variable is only accessible in this block’@v_context_level = ‘this varible is accessible in all context blocks’endcontext ‘when the user is admin’ do# Intialize the variables that will be used in all it block tests within this context blockbefore dov_block = ‘this variable is only accessible in this block’@v_it_level = ‘this varible is accessible in all it blocks’endit ‘must has admin role’ do# Code goes here. Examples: http://ruby-doc.org/stdlib-1.9.3/libdoc/minitest/spec/rdoc/MiniTest/Expectations.html# must_be# must_be_empty# must_be_nil# must_be_same_as# must_equal# must_raise# wont_be# wont_be_nil# wont_equal# wont_includeendit ‘must redirect to admin management page’ do# Code goes here, example:# assert_redirected_toendendcontext ‘when the user is not admin’ doit ‘must not have admin role’ doendit ‘must redirect to non-admin management page’ doendendenddescribe ‘#controller_action_2′ do# Code goes hereendprivate# Helper functions goes here
end

Some reminder:

1. Given, When, Then

2. Use fixture instead of creating data on the go

3. If no Before block, don't need to use context

Rails Minitest style 指南相关推荐

  1. 码住!Flink Contributor 速成指南

    简介: 不管初衷是什么,Flink 都非常欢迎大家一起建设和完善社区.在开始具体的贡献步骤之前,我们先简要介绍一下参与贡献的几种途径,以及 Clarify 关于开源贡献的一些固有印象. 作者:伍翀(云 ...

  2. github.com/stretchr/testify/suite

    Go 单元测试 https://blog.csdn.net/weixin_39172380/article/details/88666479?utm_medium=distribute.pc_rele ...

  3. 为什么微软员工可以不奋斗?

    跟国内众多科技公司比起来,微软简直是"奇葩"!这不,微软苏州团队的实习生们合伙开发了一款小工具"奋斗逼检测器"--每晚随机抽查组员Teams的在线状态,只要检测 ...

  4. 最早开始WFH的人,已经被逼着996了……

    8月7日,美国新冠肺炎感染人数突破500万,为保证员工安全,大厂陆续发布了延长WFH(Work From Home)办公时间的通知. Google宣布延长WFH到明年7月后: Facebook表示将允 ...

  5. 早早拿到offer,却迟迟入不了职

    "我早早拿到了offer,因为疫情入职时间一拖再拖.打电话问hr是不是被撤销了,hr告诉我还要再等等.今年virtual onboard怎么就这么难-" Virtual onboa ...

  6. 互联网后浪盘点:“无敌破坏王”们是怎么打破行业格局的?

    根据CNBC的第八届的Disruptor 50排行榜,诸多企业在新冠疫情中逆势而起.当别的企业还在为破产.裁员焦虑时,这些公司却成了疫情的得益者,大举融资.招聘,积极推进IPO,很有叫板传统大厂的势头 ...

  7. 程序员猪队友,差到大家都害怕他提交代码...

    知乎上有个问题: 一个程序员的水平能差到什么程度? 下面有一个经典回答: 差到大家都害怕他提交代码 Coding Style不好的同学表示有被冒犯到.然而现实中真的有许多人光顾着刷题,却在面试中跪在了 ...

  8. 手势识别(1):基础理论

    像点击(clicks)是GUI平台的核心,轻点(taps)是触摸平台的核心那样,手势(gestures)是Kinect应用程序的核心.和图形用户界面中的数字交互不同,手势是现实生活中存在的动作.如果没 ...

  9. rails i18n模型_Rails国际化的完整指南(i18n)

    rails i18n模型 by Anastasia 由Anastasia Rails国际化的完整指南(i18n) (The Complete Guide to Rails Internationali ...

最新文章

  1. JUnit基础及第一个单元测试实例(JUnit3.8)
  2. 用net连某台电脑c盘怎么连_关于电脑的4个冷知识,恐怕90%的人连第一个都不知道!...
  3. swift_016(Swift 的闭包)
  4. 一起学nRF51xx 20 -  移植SDK蓝牙例程
  5. 机器学习初学者_绝对初学者的机器学习
  6. nginx 带宽_前端工程师不可不知的Nginx知识
  7. 3种常见的Class级别的错误
  8. Windows下一个可与其他数据集控件结合的通用的搜索框GUSIconEdit
  9. Python花式编程:多层嵌套列表扁平化
  10. CCF201412试题
  11. html跨页面传数组,如何把一个页面的对象数组传到另外一个页面,没有后台,存js_html/css_WEB-ITnose...
  12. Linux内核配置.config文件
  13. MyEclipse2014+JDK1.7+Tomcat8.0+Maven3.2 开发环境搭建
  14. 4-20mA电流光纤中继器的原理和应用
  15. 怎样用python做词云_一步一步教你如何用Python做词云
  16. python判断正数和负数教案_(完整版)正数和负数教学设计
  17. OSChina 周二乱弹 —— C 语言是个女的?
  18. Android轻松实现分享功能
  19. python导入文件方法大全
  20. 关于客户端断开连接后服务器抛出异常Connection reset

热门文章

  1. 用c语言程序编写电池管理系统,基于Freescale单片机的电池管理系统设计.doc
  2. 自带容器_什么是衬胶容器罐以及质量标准?
  3. web系统软件测试功能点,小程序、app、web测试的区别
  4. html5 视频路径加密,HTML5视频路径混淆
  5. 连接linux桌面命令,连接Linux远程桌面的四个方法
  6. 二级数据库access和mysql_二级数据库access和mysql
  7. gets函数会自动加空字符吗_Python高手都知道的内置函数,你不知道就low了
  8. 【课题总结】OpenCV 抠图项目实战(6)色彩范围抠图
  9. module 'queue' has no attribute 'Queue'解决
  10. Pyhton随机生成测试数据模块faker