[RSpec] LEVEL 1: INTRODUCTION
Install RSpec:

Describe
Lets start writing a specification for the Tweet class. Write a describe block for the Tweet model without any examples inside it.
#tweet.rb class Tweet
end
Answer:
#tweet_spec.rb describe Tweet do end
It
Now create a pending test called "can set status".
describe Tweet do
it "can set status" end

Couple of ways to make test pending:

Expectation
Now let's write the example. Go ahead and instantiate a tweet, give it the status "Nom nom nom", and test the status has been properly set to this value using an == equality matcher.
class Tweet
attr_accessor :status def initialize(options={})
self.status = options[:status]
end def public?
self.status && self.status[0] != "@"
end
end
Answer:
describe Tweet do
it 'can set status' do
tweet = Tweet.new
tweet.status = "Nom nom nom"
tweet.status.should == "Nom nom nom"
end
end



Matchers
Using a predicate 'be' matcher, make sure that a tweet like "Nom nom nom" (which is not a reply because it doesn't start with an '@' sign) is public.
describe Tweet do
it 'without a leading @ symbol should be public' do
tweet = Tweet.new(status: 'Nom nom nom')
tweet.should be_public
end
end
Comparison Matchers
Finish the example below to ensure that our tweet.status.length is less than or equal to 140 characters. Use a be matcher in your spec.
class Tweet
attr_accessor :status def initialize(options={})
self.status = options[:status]
end def public?
self.status && self.status[0] != "@"
end def status=(status)
@status = status ? status[0...140] : status
end
end
Answer:
describe Tweet do
it 'truncates the status to 140 characters' do
tweet = Tweet.new(status: 'Nom nom nom' * 100)
tweet.status.length.should be <= 140
end
end
Predict 'be':

[RSpec] LEVEL 1: INTRODUCTION的更多相关文章
- [RSpec] LEVEL 2 CONFIGURATION & MATCHERS
Installing RSpec In this level we'll start by getting you setup on a regular Ruby project, then move ...
- ARMV7-M数据手册---Part A :Application Level Architecture---A1 Introduction
1.前言 本章主要介绍了ARMV7体系结构及其定义的属性,以及本手册定义的ARMV7M属性. 主要包括: ARMV7体系结构和属性 ARMV7M属性 ARMV7M扩展 2. ARMV7体系结构和属性 ...
- SQL Server索引进阶:第一级,索引简介
这个并不是我翻译的,全文共有15篇,但我发现好多网站已经不全,所以自己整理. 原文地址: Stairway to SQL Server Indexes: Level 1, Introduction t ...
- Sql Server 查询多行并一行
干货 CREATE TABLE #benefit_code21 (id INT, number nvarchar(MAX), pname ), collegeID INT, applicationda ...
- (一)ROS系统入门 Getting Started with ROS 以Kinetic为主更新 附课件PPT
ROS机器人程序设计(原书第2版)补充资料 教案1 ROS Kinetic系统入门 ROS Kinetic在Ubuntu 16.04.01 安装可参考:http://blog.csdn.net/zha ...
- A chatroom for all! Part 1 - Introduction to Node.js(转发)
项目组用到了 Node.js,发现下面这篇文章不错.转发一下.原文地址:<原文>. ------------------------------------------- A chatro ...
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- mongoDB index introduction
索引为mongoDB的查询提供了有效的解决方案,如果没有索引,mongodb必须的扫描文档集中所有记录来match查询条件的记录.然而这些扫描是没有必要,而且每一次操作mongod进程会处理大量的数据 ...
- Introduction - SNMP Tutorial
30.1 Introduction In addition to protocols that provide network level services and application progr ...
随机推荐
- BZOJ2754 [SCOI2012]喵星球上的点名 SA+莫队+树状数组
题面 戳这里 题解 首先先把所有给出的姓名和询问全部接在一起,建出\(height\)数组. 某个串要包含整个询问串,其实就相当于某个串与询问串的\(lcp\)为询问串的长度. 而两个后缀\(Suff ...
- 【2-SAT】HDU3622-Bomb Game
[题目大意] 给n对炸弹可以放置的位置(每个位置为一个二维平面上的点),每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸的范围半径都一样,控制爆炸的半径使得所有的爆炸范围都不相交(可以相切) ...
- 【四边形不等式】noi95- 合并石子
[题目大意] 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分.试设计出1个算法,计算出将N堆石子合并成 ...
- 求矩阵主对角线元素的和 Exercise08_02
import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年12月 * 题目:求矩阵主对角线元素的和 * */ public class Exercis ...
- PHP 登录DEMO
logintest.php 页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...
- [转]Android:异步处理之AsyncTask的应用(二)
2014-11-07 既然UI老人家都这么忙了,我们这些开发者肯定不能不识趣的去添乱阻塞UI线程什么的,否则UI界面万一停止响应了呢——这不是招骂的节奏么?!所以我们知道用Handler+Th ...
- 【原】Eclipse更改字符编码,精华版
- HDU 4618 Palindrome Sub-Array 暴力
Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...
- IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) C. Bear and Up-Down 暴力
C. Bear and Up-Down 题目连接: http://www.codeforces.com/contest/653/problem/C Description The life goes ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...