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_examples
orshared_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 ...
随机推荐
- fcitx jdk maven profile配置
#小企鹅输入法配置 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XMODIFIERS="@im=fcitx&quo ...
- LDA(文档主题模型)
LSA latent semantic analysis 映射词-文档到一个低维隐语义空间 比较词和文档在低纬空间的相似性 topic 是 Vocab 上的概率分布(符合多项式分布) 文档到主题的一个 ...
- CentOS7安装问题及解决方案记录
CentOS7系统已安装好: 一.我想要实现系统桌面化. 需要运行 yum 命令. 出现第一个error: 1.提示错误:can not find a valid baseurl 86_X64.... ...
- C#,委托,匿名委托,Lambda表达式
1. 委托是什么? (1) 从数据结构来讲,委托是和类一样是一种用户自定义类型. (2) 从设计模式来讲,委托(类)提供了方法(对象)的抽象.概括的说:委托是方法的抽象. 2. 委托类型的定义: 委 ...
- centos 6.5 msyql5.6安装
MySQL 安装 安装mysql前需要查询系统中含有的有关mysql的软件. rpm -qa | grep -i mysql 如下 代表有mysql ,则先进行卸载 mysql-libs-5.1. ...
- 初学c# -- 学习笔记(二)
接着前面的学习,对话建立了,下面就写对话框气泡,和微信的差不多那种.尖角对话气泡网上一堆,圆尖角的修改了一个.IE8以下不能用,其他都可以用,直接上html代码,将<style>内容用到你 ...
- jquery的滑动
(1)slideDown(speed,callback)方法:用于想下滑动的方法. $("#flip").click(function(){ $("#panel" ...
- jQuery插件制作方法
html页面:<h1>Hello My name is Alex,i from china.</h1> 1.无参数实现文字阴影效果 测试代码: $("h1" ...
- C# 配置文件 AppSettings和ConnectionStrings的区别
web.config是web应用程序的配置文件,为web应用程序提供相应配置(B/S).app.config是桌面应用程序的配置文件,为桌面应用程序提供相应配置(C/S).Configuratio ...
- thinkphp model模块
1.获取系统常量信息的方法:在控制器DengLuController里面下写入下面的方法,然后调用该方法. public function test() { //echo "这是测试的&qu ...