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. 洛谷P2704 [NOI2001]炮兵阵地 [状压DP]

    题目传送门 炮兵阵地 题目描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用“H” 表示),也可能是平原(用“P”表示),如下图 ...

  2. hibernate-release-4.3.11.Final资源包介绍

    资源下载 hibernate-release-4.3.11.Final documentation 包  相关文档 lib  相关jar包 required --开发中必须要加入的包 optional ...

  3. [BZOJ4553][TJOI2016&&HEOI2016]序列(CDQ分治)

    4553: [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1202  Solved: 554[Su ...

  4. [ZROI 9.16模拟赛] Tutorial

    Link: 传送门 A: 套路题结果想了好久…… 排序二叉树的性质就是中序遍历单调递增 于是只考虑当前树的中序遍历的序列即可,与树的形态无关 将序列改成严格单调增想到最大化不变的数,但直接LIS求的是 ...

  5. hdu 1533 KM或费用流

    以前用KM写过,现在再用费用流写. #include <iostream> #include <cstdio> #include <cstring> #includ ...

  6. 人脸检测:微软 VS Face++

    近些年国内的人脸技术已经得到了很大的发展,今天网上无意看到了微软和face++两家公司的人脸检测,Face++号称国际顶尖的技术,也用过他们的接口感觉确实很不错,而微软则不再话下了.于是想对比微软和F ...

  7. Ubuntu下deb包的安装方法 - kevinhg的博客 - 博客频道 - CSDN.NET

    Ubuntu下deb包的安装方法 - kevinhg的博客 - 博客频道 - CSDN.NET dpkg -i

  8. require(): open_basedir restriction in effect. 解决方法

    在linux服务器部署thinkphp5的时候PHP报了这个错误, 如下: Warning: require(): open_basedir restriction in effect. File(/ ...

  9. Qt移动应用开发(八):实现跨平台的QML和OpenGL混合渲染

    Qt移动应用开发(八):实现跨平台的QML和OpenGL混合渲染 上一篇文章讲到了利用C++这个桥梁,我们实现了QML和Java的交互.Qt 5大力推崇的QML/JS开发,让轻量.高速开发的QML/J ...

  10. How to let TVirtualStringTree to display an icon in disabled state?

    How to let TVirtualStringTree to display an icon in disabled state? I need to display files in a dir ...