Rails Minitest style 指南

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


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/570527.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

浅谈离散数学中数理逻辑与集合论的数学本质

申华 , 张胜元 - 《大学教育》 - 2013 离散数学本质上是一门数学课程&#xff0c;是学生数学知识结构和数学素质的重要组成部分。数学这门学科体系虽然很庞大&#xff0c;但大致可分为连续型、离散型和随机型这三大类。在大多数的理工科专业的课程设计中&#xff0c;数学…

Rails用DELETE method提交表单讲解

Sometimes we need to submit form using methods other than ‘post’, in this example, it’s ‘delete’. For example, I wanted to delete a user when a form is submitted with the user name and ‘delete’ method. 1. I created the route like this: delete ‘test…

【PAT】B1055 集体照(25 分)

很简单的two points问题 ##注意&#xff1a;K是行数 #include<stdio.h> #include<string.h> #include<map> #include<vector> #include<algorithm> using namespace std; struct people{char name[10];int height; }arr[10005]; bool cmp(people…

luogu 4768

kruskal 重构树对于一张无向图&#xff0c;我们在进行 kruskal 的过程中每当合并两个联通块时新建虚拟节点 t对于两个联通块的根节点 fau&#xff0c;fav 连无向边(fau, t)&#xff0c;(fav, t) 其中点 t 的点权为两个联通块当前连边的边权对于这道题首先 dijkstra 处理所有点到…

使用DreamHost当GoDaddy域名的服务器 步骤

1. 在GoDaddy管理员页面中改变DNS设置&#xff0c;指向DreamHost Name servers&#xff1a; 进入Domain details page: 目前在 SETTINGS -> Nameservers. 数值还是默认值: NS11.DOMAINCONTROL.COM NS12.DOMAINCONTROL.COM 我们需要将它修改为 DreamHost nameservers: …

PAT乙级1011.A+B和C (15)(15 分)

给定区间[-2^31^, 2^31^]内的3个整数A、B和C&#xff0c;请判断AB是否大于C。 输入格式&#xff1a; 输入第1行给出正整数T(<10)&#xff0c;是测试用例的个数。随后给出T组测试用例&#xff0c;每组占一行&#xff0c;顺序给出A、B和C。整数间以空格分隔。 输出格式&#x…

有用的 Google Analytics Chrome 插件推荐

1.Google Analytics Debugger Debbuger 会列出所有执行的命令以及传过去的参数。 例如&#xff0c;常见的命令有&#xff1a; 初始化 Google Analytics&#xff0c; 传送页面访问 和传送事件。 https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmf…

项目计划定制:项目计划划分与产品项目推进的有机结合

目录&#xff1a; 第一章&#xff1a;导语第二章&#xff1a;需求采集部分的一些要点第三章&#xff1a;项目中一些需要明确的内容第四章&#xff1a;关于成本管理部分第一章&#xff1a;导语 那么什么叫项目&#xff0c;项目计划和项目管理&#xff1f; 项目管理简称为PM&…

Rails 使用 Google Analytics 示例

1. 创建 _google_analytics.html.erb view: <span style"font-size:18px;"><!-- Google Analytics -->window.gawindow.ga||function(){(ga.qga.q||[]).push(arguments)};ga.lnew Date;// Create tracker.ga(create, <% ENV[GOOGLE_ANALYTICS_TRACKI…

爬虫_微信小程序社区教程(crawlspider)

照着敲了一遍&#xff0c;&#xff0c;&#xff0c; 需要使用"LinkExtrator"和"Rule"&#xff0c;这两个东西决定爬虫的走向。 1.allow设置规则的方法&#xff1a;要能够限制在我们想要的url上&#xff0c;不要跟其他的url产生相同的正则表达式即可 2.什么…

开始使用Google Analytics 示例

1. 创建一个 Google Analytics 账户. 2. 创建新的 property: 在左上角点击 Admin。 然后在 Property 标签下面&#xff0c;点击以展开下拉菜单&#xff1a; 选择"create new property": 3. 填写所有必须填写的框: 建议打开 In-page analysis: What is in-page ana…

数据库连接池优化配置(druid,dbcp,c3p0)

主要描述了数据库连接池参数配置的准则&#xff0c;针对常用的数据库连接池(c3p0,dbcp,druid)给出推荐的配置。 考虑因素 1&#xff1a;当前连接DB的规模 2&#xff1a;并发情况 3&#xff1a;执行db的响应时间 配置考虑 1&#xff1a;初始化连接&#xff1a;可考虑设置为…

Windows系统上3种连接Docker虚拟机的方法

1.Docker Quickstart Terminal 打开 "Docker Quickstart Terminal" 然后输入 $ docker-machine ssh <docker machine name> 此处Docker虚拟机的名字是default&#xff1a; 2. gitBash 打开 "gitBash" &#xff0c;然后输入&#xff1a; $ docker-ma…

P2258 子矩阵

题目描述 给出如下定义&#xff1a; 子矩阵&#xff1a;从一个矩阵当中选取某些行和某些列交叉位置所组成的新矩阵&#xff08;保持行与列的相对顺序&#xff09;被称为原矩阵的一个子矩阵。例如&#xff0c;下面左图中选取第 222 、 444 行和第 222 、 444 、 555 列交叉位置的…

Windows 系统安装Docker Compose 步骤

参考 Docker Compose official 官方安装指南: https://docs.docker.com/compose/install/ 实际上到目前为止还不能直接在Windows上安装Docker Compose&#xff0c;所以这篇文章要讲的是如何在Windows上使用Docker Compose。 先决条件: Docker Machine 已经安装完毕。 解决方案:…

vagrant box各种命令汇总

最近在研究laravel&#xff0c;中间用到了vagrant 虚拟机管理工具&#xff0c;学习一下他的命令 vagrant box命令 用于管理boxes的命令&#xff0c;比如添加、删除等等。 此命令的功能主要通过以下子命令完成&#xff1a; add list outdated prune remove repackage update Box…

运行第一个 docker image 并在浏览器中查看

1. SSH to Docker 虚拟机. 打开gitBash或者Docker Quickstart Terminal, 并且输入: <span style"font-size:14px;">$ docker-machine ssh <docker machine name></span>如需要更详细的如何连接Docker Machine的介绍&#xff0c;可以参考我的另一篇…

js_!和!!的使用

js中有些特殊的数据&#xff08;“” 0 null undefined NaN&#xff09;,请求后台返回的数据中往往都有一些这样的数据&#xff0c;需要对这些数据进行过滤。 过滤代码 var a 0;//0 "" null undefined NaN //如果有内容不为&#xff08;0 "" null undefi…

Fixed Function Shader

Fixed function shader(固定管线着色器) Shader "Custom/Text01" { //shader名称 Properties   Shader属性 { //定义一个名称为Main Color属性 _Color ("Main Color", Color) (1,0.5,0.5,1) _SpecularColor("高光颜色"…

linux 时间同步ntp

配置前准备:关闭防火墙,配置好hosts,ssh免密登录 1.选定同步的标准,我是以hadoop002(设置为当前时间)作为同步标准,hadoop003(时间是2018年3月21,使用date -s进行设置)与hadoop004(2018年3月21)与之保持同步 在hadoop002上查看是否安装ntp rpm -qa|grep ntp,如果没有显示内容说…