rspec中的shared_examples与shared_context有什么不同
What is the real difference between shared_examples and shared_context ?
My observations :
I can test same things using both (i.e. with
shared_examplesorshared_context)But some of my other tests fails if I use later one.
Observation #1 :
I compared shared_examples and shared_context per documentation onhttps://www.relishapp.com/
Syntactical differences are :
- shared_context to define a block that will be evaluated in the context of example groups by implicitly matching metadata
Example :
shared_context "shared stuff", :a => :b do
...
end
- The way these are included or called from a test file
shared_examples
include_examples "name" # include the examples in the current context
it_behaves_like "name" # include the examples in a nested context
it_should_behave_like "name" # include the examples in a nested context
shared_context
include_context "shared stuff"
Observation #2
I have a test case
shared_context 'limit_articles' do |factory_name|
before do
@account = create(:account)
end
it 'should restrict 3rd article' do
create_list(factory_name, 3, account: @account)
article4 = build(factory_name, account: @account)
article4.should be_invalid
end
it 'should allow 1st article' do
...
end
it 'should allow 2nd article' do
...
end
end
And include the context in a spec file which already has one shared_context included, then the existing one fails. But I change the order then all my test passes
Fails
include_context 'existing_shared_context'
include_context 'limit_articles'
Also if I replace the shared_context with shared_examples and accordingly include it in test case.
Passes
include_context 'existing_shared_context'
it_behaves_like 'limit_articles'
原文:http://stackoverflow.com/questions/21117123/rspec-shared-examples-vs-shared-context
rspec中的shared_examples与shared_context有什么不同的更多相关文章
- rspec中的let和let!区别
文档 https://relishapp.com/rspec/rspec-core/v/2-5/docs/helper-methods/let-and-let 从上面文档中得出 let 1 只会在一个 ...
- Rspec中describe和context不同
转自 http://lmws.net/describe-vs-context-in-rspec 学习rspec,不太理解describe和context.google了一下,找到这篇文章,感觉说的有 ...
- Rails中的测试RSpec升级遇到的问题
bundle exec rspec spec/ /home/wuxj/Prac/rrprac/sample_app/spec/spec_helper.rb::in `block in <top ...
- rspec的一些常见用法
这里讲了如何安装rspec,安装使用rspec. 下面介绍一下rspec中常见的使用方法. 下面是一个最简单的测试用例,判断true是不是等于true,should_be是旧的用法,新用法推荐使用ex ...
- Rspec: feature spec 功能测试 测试JavaScript.
我们要把应用各组件放在一起做集成 测试,这样才能保证模型和控制器之间能够良好契合. 在 RSpec 中,这种测试称为功能测试(feature spec),有时也称为验收测试(acceptance te ...
- Ruby之Rspec的报错解决
#enconding:utf-8 require 'selenium-webdriver' require 'rspec' describe "baidu main page" d ...
- pundit
gem "pundit" Include Pundit in your application controller: class ApplicationController &l ...
- 有意练习--Rails RESTful(一)
书要反复提及<哪里有天才>在说,大多数所谓的天才是通过反复刻意练习获得. 当你的练习时间达到10000几个小时后,.你将成为该领域的专家. 近期在学习rails怎样实现RESTful We ...
- BDD
Binding business requirements to .NET code http://www.specflow.org/ 行为驱动开发 BDD:Behavior Driven Devel ...
随机推荐
- [Altera]PLL仿真
EDA Tools: 1.Quartus II 13.1(64-bit) 2.Modelsim SE-64 10.1c Time: 2016.05.05 ----------------------- ...
- BeanUtils.populate的作用
它是在org.apache.commons.beanutils.BeanUtils包中的一个方法. 方法的作用:将一些 key-value 的值(例如 hashmap)映射到 bean 中的属性. ...
- RHCA-红帽认证架构师
OpenStack: 向部署应用 配置域.数据源子系统.中实施应用安全 迁移应用至 介绍集群 考试代码 任选其中五门: (红帽企业虚拟化) (红帽企业部署和系统管理) (红帽企业服务器硬化) (红帽企 ...
- jsonp原理
http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html
- funny_python 00 The Zen of Python
# 打算每天多动的时候尽量搜索一些和coding相关的funny stuff Day 00 - PEP 20 The Zen of Python 在shell里面输入python -m this 回车 ...
- LINQ to XML 编程基础
1.LINQ to XML类 以下的代码演示了如何使用LINQ to XML来快速创建一个xml: 隐藏行号 复制代码 ?创建 XML public static void CreateDocumen ...
- extern extern “C”用法详解
1.extern 修饰一个变量,告诉编译器这个变量在其他地方定义,编译器不会给出变量未定义的警告. extern tells the compiler that the variable is def ...
- 网络TCp数据的传输设计(黏包处理)
//1.该片为引用别人的文章:http://www.cnblogs.com/alon/archive/2009/04/16/1437599.html 解决TCP网络传输"粘包"问题 ...
- asp.net 琐记
Page的AutoEventWireup作用是是否引发PreInit Load PreRender Unload几个页面处理流程事件 和控件的事件处理函数无关
- 使用HttpClient 发送get、post请求,及其解析xml返回数据
一.关于HttpClient的使用: 可以参考这个博客地址,这里有详细的介绍,需要的可以先看一下: 地址是:http://blog.csdn.net/wangpeng047/article/detai ...