Rspec中describe和context不同
转自 http://lmws.net/describe-vs-context-in-rspec
学习rspec,不太理解describe和context。google了一下,找到这篇文章,感觉说的有些道理
1 在Rspec的世界里,我们经常看到人们使用descirbe代码块和context代码块 例如
describe "launch the rocket" do
context "all ready" do
end context "not ready" do
end
end
那么context和descript有啥不同呢
According to the rspec source code, “context” is just a alias method of “describe”, meaning that there is no functional difference between these two methods. However, there is a contextual difference that’ll help to make your tests more understandable by using both of them.
说的是,按照rspec源码来看,context仅仅是describe方法的别名,意味着这两者没有任何功能性的不同, 然而有一些语境不同(语义不同),理解这个能让你写出更可读的代码
The purpose of “describe” is to wrap a set of tests against one functionality while “context” is to wrap a set of tests against one functionality under the same state. Here’s an example
describe的目的是当它包裹一组,一个功能,的测试代码
context的目的是包裹一组,在同一状态下,一个功能的,测试代码
例如下面代码
describe "launch the rocket" do
before(:each) do
#prepare a rocket for all of the tests
@rocket = Rocket.new
end context "all ready" do
before(:each) do
#under the state of ready
@rocket.ready = true
end it "launch the rocket" do
@rocket.launch().should be_true
end
end context "not ready" do
before(:each) do
#under the state of NOT ready
@rocket.ready = false
end it "does not launch the rocket" do
@rocket.launch().should be_false
end
end
end
上面的代码可读性好在,没有将所有东西都用describe包裹,因为你读测试代码是在context语境内,对于一个context设置一个对象状态,
@rocket.ready为true时, @rocket.launch() 的行为,导致一个结果,如果只关注一个这个状态时,火箭的启动结果,就不需要再看其他状态的代码
Rspec中describe和context不同的更多相关文章
- android开发中fragment获取context
在用到fragment时无法使用.this来指定当前context内容,android开发中fragment获取context,可以使用getActivity().getApplicationCont ...
- Android应用开发中关于this.context=context的理解
在Android应用开发中,有的类里面需要声明一个Context的成员变量,然后还需要在该类的构造函数中加上this.context=context;这行代码.为什么要这么写呢?不写不行么? 先看下面 ...
- HttpHandler中无法使用Session(context.Session 为Null)
一.问题描述: 最近需要做一个对特定请求(.report)进行响应的接口,当然是使用实现IHttpHandler来进行处理,实现IHttpHandler接口就必须要实现它的两个方法,ProcessRe ...
- Spring.xml中配置注解context:annotation-config和context:component-scan简述
XML中context:annotation-config和context:component-scan简述 <context:annotation-config/> 中文意思:<上 ...
- mysql中describe关键字
今天写代码的时候,有一个类的数据始终不能插入,老是提示在You have an error in your SQL syntax; check the manual that corresponds ...
- android中LayoutInflater.from(context).inflate的分析
在应用中自定义一个view,需要获取这个view的布局,需要用到 (LinearLayout) LayoutInflater.from(context).inflate(R.layout.conten ...
- rspec中的let和let!区别
文档 https://relishapp.com/rspec/rspec-core/v/2-5/docs/helper-methods/let-and-let 从上面文档中得出 let 1 只会在一个 ...
- spring中注解注入 context:component-scan 的使用说明
通常情况下我们在创建spring项目的时候在xml配置文件中都会配置这个标签,配置完这个标签后,spring就会去自动扫描base-package对应的路径或者该路径的子包下面的java文件,如果扫描 ...
- 深入理解 Android 中的各种 Context
前言 网上关于 Context 的文章也已经有不少了,比如值得参考的有: Android Context完全解析,你所不知道的Context的各种细节 Android Context 到底是什么? 但 ...
随机推荐
- C#中调用C++的dll的参数为指针类型的导出函数(包括二级指针的情况)
严格来说这篇文章算不上C++范围的,不过还是挂了点边,还是在自己的blog中记录一下吧. C++中使用指针是家常便饭了,也非常的好用,这也是我之所以喜欢C++的原因之一.但是在C#中就强调托管的概念了 ...
- VC++ 0xC0000005: Access violation.
public: COptionDlg(CWnd* pParent = NULL); // 标准构造函数 virtual ~COptionDlg(); TCONFIG m_tCfg; // 对话框数据 ...
- lucene 基本原理整理
基本原理:http://www.cnblogs.com/forfuture1978/archive/2009/12/14/1623594.html 所有过程:http://www.cnblogs.co ...
- 进程kswapd0与events/0消耗大量CPU的问题
http://www.nowamagic.net/librarys/veda/detail/2539 今天下午网站宕了两次机,发工单给阿里云,发现原因是服务器的CPU 100%了. 重启服务器后,使用 ...
- 如何将SQL Server 2008库导入2000中
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- PostgreSQL数据的导出导入
PostgreSQL数据的导出导入 导出PostgreSQL数据库中的数据: $ pg_dump -U postgres -f mydatabase.sql mydatabase 导入数据时首先创 ...
- Swift使用Alamofire实现网络请求
Alamofire是一个用Swift编写的HTTP网络库,由此前热门开源项目AFNetworking的的作者mattt开发,可非常简单地用于异步网络通信. 要获取最新版本的 Alamofire,前往h ...
- Google将数十亿行代码储存在单一的源码库
过去16年,Google使用一个中心化源码控制系统去管理一个日益庞大的单一共享源码库.它的代码库包含了约10亿个文件(有重复文件和分支)和 3500万行注解,86TB数据,900万唯一源文件中含有大约 ...
- HadoopDoctor:来自腾讯数据仓库TDW的MR诊断系统
TDW是基于Hadoop生态圈研发的大数据处理平台,MapReduce计算引擎在TDW平台中承担了所有的离线数据计算,是TDW最重要的底层支撑平台之一.在TDW 平台中,除了MR程序会生成MapRed ...
- J2EE分布式事务中的提交、回滚方法调用异常。
这个是昨天上班的时候,写一个后台程序的调试程序时碰到的问题,和项目经理纠结了一天,最后搞定了.于是今天上班正好闲着,花了几乎一天的时间去网上找各种相关的资料.目前了解的内容如此: 根据使用的weblo ...