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的更多相关文章

  1. [RSpec] LEVEL 2 CONFIGURATION & MATCHERS

    Installing RSpec In this level we'll start by getting you setup on a regular Ruby project, then move ...

  2. ARMV7-M数据手册---Part A :Application Level Architecture---A1 Introduction

    1.前言 本章主要介绍了ARMV7体系结构及其定义的属性,以及本手册定义的ARMV7M属性. 主要包括: ARMV7体系结构和属性 ARMV7M属性 ARMV7M扩展 2. ARMV7体系结构和属性 ...

  3. SQL Server索引进阶:第一级,索引简介

    这个并不是我翻译的,全文共有15篇,但我发现好多网站已经不全,所以自己整理. 原文地址: Stairway to SQL Server Indexes: Level 1, Introduction t ...

  4. Sql Server 查询多行并一行

    干货 CREATE TABLE #benefit_code21 (id INT, number nvarchar(MAX), pname ), collegeID INT, applicationda ...

  5. (一)ROS系统入门 Getting Started with ROS 以Kinetic为主更新 附课件PPT

    ROS机器人程序设计(原书第2版)补充资料 教案1 ROS Kinetic系统入门 ROS Kinetic在Ubuntu 16.04.01 安装可参考:http://blog.csdn.net/zha ...

  6. A chatroom for all! Part 1 - Introduction to Node.js(转发)

    项目组用到了 Node.js,发现下面这篇文章不错.转发一下.原文地址:<原文>. ------------------------------------------- A chatro ...

  7. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  8. mongoDB index introduction

    索引为mongoDB的查询提供了有效的解决方案,如果没有索引,mongodb必须的扫描文档集中所有记录来match查询条件的记录.然而这些扫描是没有必要,而且每一次操作mongod进程会处理大量的数据 ...

  9. Introduction - SNMP Tutorial

    30.1 Introduction In addition to protocols that provide network level services and application progr ...

随机推荐

  1. Latex 学习之旅

    学习资料 A simple guide to LaTeX - Step by Step LaTeX WikiBook LaTeX 科技排版 TeXdoc Online (TeX and LaTeX d ...

  2. JSTL-3

    .循环标签:forEach标签, forTokens标签 <c:forEach>:标签:该标签根据循环条件遍历集合(Collection)中的元素 <c:forEach [var=& ...

  3. Web应用类型扫描识别工具WhatWeb

    Web应用类型扫描识别工具WhatWeb   WhatWeb是一款Kali Linux预安装的Web扫描工具.它使用Ruby语言编写.该工具可以扫描网站,获取该网站的各类信息,如所使用的CMS.博客平 ...

  4. HDU 2222 Keywords Search 【AC自动机】

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=2222] 题意:给出很多小字符串,然后给出一个文本串,问文本串中包含多少个小字符串.也就是说如果文本串 ...

  5. [Usaco2015 Feb]Censoring --- AC自动机 + 栈

    bzoj 3940 Censoring 题目描述 FJ把杂志上所有的文章摘抄了下来并把它变成了一个长度不超过10^5的字符串S. 他有一个包含n个单词的列表,列表里的n个单词记为T1......Tn. ...

  6. poj 2912 并查集(食物链加强版)

    题目:给出n个人玩剪刀石头布的游戏,其中有一个人是裁判,剩下的人分为3组,每一组的人只出某一种手型,裁判可以任意出.问是否能判断出哪个人是裁判 链接:点我 分分钟看吐血,先把食物链看懂吧 枚举裁判,然 ...

  7. mpdf与fpdf的使用比较

    php扩展 ---mpdf/fpdf 最近用到pdf扩展,需求是生成合同与简历的pdf,可供下载打印 mpdf 首先接触的是mpdf,从源码可以看出mpdf是基于fpdf与html2fpdf的成果. ...

  8. AC自动机详解(附加可持久化AC自动机)

    AC自动机 AC自动机,说白了就是在trie树上跑kmp(其实个人感觉比kmp容易理解).是一种多匹配串,单个主串的匹配.概括来说,就是将多个匹配串构造一个trie树,对于每个trie树的节点构造nx ...

  9. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  10. Matlab 曲线绘制之线型和颜色 示例

    估计很多人会碰到,当绘制的曲线特别多的时候,需要用不同的颜色和线型区分开这些曲线.根据STC论文,自己整理了一个颜色和线型的例子,供大家直接使用,直接引用PlotStyle这个数据结构就可以了. 示例 ...