[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 ...
随机推荐
- 基于rsync方式的文件备份
rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用.本文主要讲述的是如何自架rsync服 务器,以实现文件传输.备份和镜像.相对ta ...
- javascript中Date对象的应用
前面的话 简易日历作为javascript中Date对象的常见应用,用途较广泛.本文将详细说明简易日历的实现思路 效果演示 HTML说明 使用type=number的两个input分别作为年和月的输入 ...
- Redis学习篇(八)之连接相关
PING 测试客户端和服务器之间的连接是否有效,有效返回PONG ECHO 打印特定的信息, 如: ECHO 'HELLO WORLD' QUIT/EXIT 断开当前客户端与服务器之间的连接,可以重连 ...
- FastReport.Net使用:[17]线(Line)控件使用
FastReport中,线(Line)控件怎么用?怎么画一条美观的线? 认识Line控件 1.线(Line)控件包含于形状(Shape)控件中,有5个可选项,一个标准线和四个对角线,其实都是同一种线, ...
- eclipse 的alt shift a,r 这个快捷键怎么操作 怎么按 eclipse 快捷键 逗号 什么意思
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha eclipse 的alt shift a,r 这个快捷键怎么操作 怎么按 eclipse ...
- BZOJ4599[JLoi2016&LNoi2016]成绩比较(dp+拉格朗日插值)
这个题我们首先可以dp,f[i][j]表示前i个科目恰好碾压了j个人的方案数,然后进行转移.我们先不考虑每个人的分数,先只关心和B的相对大小关系.我们设R[i]为第i科比B分数少的人数,则有f[i][ ...
- QTREEⅠ SPOJ
树剖模板,注意把边化为点后要查到y的儿子. #include<bits/stdc++.h> using namespace std; ; int f[N],bel[N],w[N],id[N ...
- [BZOJ5109][LOJ #6252][P4061][CodePlus 2017 11月赛]大吉大利,今晚吃鸡!(最短路+拓扑排序+传递闭包+map+bitset(hash+压位))
5109: [CodePlus 2017]大吉大利,晚上吃鸡! Time Limit: 30 Sec Memory Limit: 1024 MBSubmit: 107 Solved: 57[Sub ...
- Linux sort 排序 去重 统计
先写一个命令: cut -d' ' -f1 ~/.bash_history|sort -d | uniq -c|sort -nr|head 这个命令可以统计你历史上输入的命令的次数的前十条 整个命令基 ...
- 压测工具Webbench
webbench最多可以模拟3万个并发连接去测试网站的负载能力,安装使用也特别方便,并且非常小. 1.系统:Linux 2.编译安装: [root@~]$wget http://blog.s135.c ...