Rails Minitest style 指南
来源:互联网 发布:梦幻西游mac安装打不开 编辑:程序博客网 时间:2024/05/21 23:49
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 < ApplicationController def controller_action_1 # Code goes here end def controller_action_2 # Code goes here endend
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 class before do v_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 1 describe ‘#controller_action_1′ do # Intialize the variables that will be used in all context block tests within this describe block before do v_block = ‘this variable is only accessible in this block’ @v_context_level = ‘this varible is accessible in all context blocks’ end context ‘when the user is admin’ do # Intialize the variables that will be used in all it block tests within this context block before do v_block = ‘this variable is only accessible in this block’ @v_it_level = ‘this varible is accessible in all it blocks’ end it ‘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_include end it ‘must redirect to admin management page’ do # Code goes here, example: # assert_redirected_to end end context ‘when the user is not admin’ do it ‘must not have admin role’ do end it ‘must redirect to non-admin management page’ do end end end describe ‘#controller_action_2′ do # Code goes here end private # Helper functions goes hereend
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
0 0
- Rails Minitest style 指南
- Rails Rake指南
- Rails Rake 指南
- rails入门指南
- REST on Rails指南
- Rails 初上手指南
- Rails Rake指南
- Ruby on Rails 指南
- MiniTest学习笔记
- MINItest软件架构总结
- Ruby on Rails 3 Style Guide。
- [Translation]Google Java Style 指南
- Ruby on Rails安装指南
- Ruby on Rails安装指南
- 一道微软MiniTest笔试题
- UnityScript风格指南(UnityScript Style Guide)
- Google Java Style 编程风格指南 中文版
- apache+fastcgi+ruby+rails 安装指南
- IOS 加入购物车动画
- 为手机应用程序(Android、iOS、WindowsPhone)添加超声波通信技术
- Java笔记:环境搭建
- Joomla开发最佳实践
- Qt 编码中的某一字从 UTF-8 转换到 UNICODE 国际化时可能用到
- Rails Minitest style 指南
- android项目中注意的问题
- 哪几种情况可以销毁session(一般有3种)
- 《重构--改善既有代码的设计》--重构,第一个案例(1)
- Java输入输出流和文件操作
- Unity3D游戏开发之路:一月工作总结
- android获取string.xml的值
- 2015.6.22学习笔记之activity的生命周期和四种启动方式
- 如何隐藏Windows7 系统保留分区