[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 ...
随机推荐
- 2018IEEE冬季生物识别学校 5天课程
里边有很多介绍及相关报告的PPT https://www.comp.hkbu.edu.hk/wsb18/index.php https://www.comp.hkbu.edu.hk/wsb18/pro ...
- asp.net core集成CAP(分布式事务总线)
一.前言 感谢杨晓东大佬为社区贡献的CAP开源项目,传送门在此:.NET Core 事件总线,分布式事务解决方案:CAP 以及 如何在你的项目中集成 CAP[手把手视频教程],之前也在工作中遇到分布式 ...
- urllib2 调用salt restapi
1获取token #_*_coding:utf8_*_ import urllib2 import json def get_token(): url='http://10.20.32.86:8000 ...
- Vue 2.0学习(五)v-bind及class与style绑定
DOM元素经常会动态地绑定一些class类名或style样式. 基本用法 <div id="app"> <a v-bind:href="url" ...
- AGC026D Histogram Coloring
link 题意: 给定n列的方块,第i列高度$h_i$.现在要把它染成红蓝两色,要求满足:对于任意一个$2\times 2$的区域,恰有2个蓝色,2个红色.问方案数. $n\leq 100,h_i\l ...
- 1.6(SQL学习笔记)存储过程
一.什么事存储过程 可以将存储过程看做是一组完成某个特定功能的SQL语句的集合. 例如有一个转账功能(A向B转账50),先将账户A中金额扣除50,然后将账户B中金额添加50. 那么我们可以定义一个名为 ...
- CodeM资格赛3
题目描述 美团点评上有很多餐馆优惠券,用户可以在美团点评App上购买.每种优惠券有一个唯一的正整数编号.每个人可以拥有多张优惠券,但每种优惠券只能同时拥有至多一张.每种优惠券可以在使用之后继续购买. ...
- StringFormat
public class StringFormatDemo { public static void main(String[] args) { String str = null; str = St ...
- 【转】如何修改maven工程jdk版本
1.使用maven的时候,默认会使用1.5版本的JDK,并且也是编译成1.5的,我的电脑里面用的JDK是1.7的,1.8也出来了,没理由还用1.5的吧!所以我手动改成了1.7,郁闷的是,每次 mave ...
- Are you sure your NDK_MODULE_PATH variable is properly defined?(2)
Are you sure your NDK_MODULE_PATH variable is properly defined? STEP1: MIND: 明确NDK_MODULE_PATH概念ht ...