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 ...
随机推荐
- Php安全规范
一.基本准则 所有的用户输入都是有害的,对所有从客户端传入的数据都不信任, 需要做判断和过滤(类型,长度,格式,范围),否则可能会受到SQL Injection.XSS等攻击.比如:$_GET, $_ ...
- Python中出现的异常
简单的写几种我知道的关于Python中出现的异常含义,希望大神批评指正,我只是学软件开发的菜鸟,前面的路还很长,我会努力学习! 什么是异常? 异常既是一个事件,该事件会在程序执行过程中发生,影响了程序 ...
- Jmeter使用入门
修改时间 修改内容 修改人 2016.3.12 创建 刘永志 2016.6.18 完成 刘永志 Jmeter简介 Jmeter的基本概念 百度百科: Apache JMeter是Apache组织开发的 ...
- UVALive - 4513 Stammering Aliens ——(hash+二分 || 后缀数组加二分)
题意:找一个出现了m次的最长子串,以及这时的最右的位置. hash的话代码还是比较好写的,,但是时间比SA多很多.. #include <stdio.h> #include <alg ...
- Android菜鸟成长记15 -- BitMap
BitMap简介 Bitmap是Android系统中的图像处理的最重要类之一.用它可以获取图像文件信息,进行图像剪切.旋转.缩放等操作,并可以指定格式保存图像文件.本文从应用的角度,着重介绍怎么用Bi ...
- Ptex源码学习笔记-1
Ptex是Walt Disney Animation Studios开发的纹理映射工具.在看一个叫appleseed的渲染器时看到他支持这种纹理,所以就查看一下,发现比较轻量,所以就想趁此机会学习下. ...
- 反汇编工具capstone安装后import error
使用sudo pip install capstone后,使用如下代码import时出现error. from capstone import * 错误信息: File "/usr/loca ...
- iOS Core Animation之CALayer心得
使用CALayer的mask实现注水动画效果 Core Animation一直是iOS比较有意思的一个主题,使用Core Animation可以实现非常平滑的炫酷动画.Core animtion的AP ...
- NPOI 2.0版本的使用
详细教程: http://blog.csdn.net/xxs77ch/article/details/50216033 using System; using System.Collections.G ...
- C#中格式化获取到的当前系统时间的各种格式
public class CustomLanguage : CultureInfo { public CustomLanguage(string shortDatePattern ...