Update rspec

This commit is contained in:
Rico Sta. Cruz 2016-09-26 17:56:33 +08:00
parent b0b9fd1fb5
commit e61d3dfc57
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
3 changed files with 198 additions and 31 deletions

View File

@ -29,7 +29,13 @@ boolean
mixed mixed
number number
string string
void void // undefined
null // null (but not undefined)
?number // maybe (number | void | null)
{a: Number} // object with a shape
[any, number] // tuples (fixed-length arrays)
Array<T> Array<T>
Class<T> Class<T>
@ -37,6 +43,56 @@ Function
Object Object
``` ```
## [Type aliases](https://flowtype.org/docs/quick-reference.html#type-aliases)
```js
type Tree = {
foo: string,
bar: number,
qux: (foo: string, bar: number) => boolean
}
type Generic<T> = {
foo: T
}
```
## [Generic classes](https://flowtype.org/docs/quick-reference.html#generics)
```js
class GenericClass<T> {
x: T;
constructor (x: T) { ... }
}
var n: GenericClass<number> = new GenericClass(0)
```
## [Interfaces](https://flowtype.org/docs/quick-reference.html#interfaces)
```js
interface Jsonable {
toJSON(): string
}
class Foo {
toJSON() { return '{}' }
}
(new Foo: Jsonable)
```
## [Functions](https://flowtype.org/docs/functions.html)
```js
function createRenderer (): () => void {
return function () { }
}
```
## Examples
```js ```js
var myNumbers: Array<number> = [42] var myNumbers: Array<number> = [42]
function foo(): any { return 42 } function foo(): any { return 42 }

88
jsdoc.md Normal file
View File

@ -0,0 +1,88 @@
---
title: Jsdoc
category: JavaScript
---
## Functions
```js
/*
* @param {string} n - A string param
* @return {string} A good string
*
* @throws {FooException}
* @private
* @deprecated
* @see
*
* @function
* @class
*/
function foo(n) { return n }
```
See: http://usejsdoc.org/index.html
## Types
```
/**
* @param {string=} n - Optional param
* @param {string} [n] - Optional param
* @param {(string|number)} n - Multiple types
* @param {*} n - Any type
* @param {...string} n - Repeatable arguments
* @param {string} [n="hi"] - Optional param with default
* @param {string[]} n - An array of strings
*/
```
See: http://usejsdoc.org/tags-type.html
## Variables
```js
/**
* @type {number}
*/
var FOO = 1
/**
* @const {number}
*/
const FOO = 1
```
## Typedef
```js
/**
* A song
* @typedef {Object} Song
* @property {string} title - The title
* @property {string} artist - The artist
* @property {number} year - The year
*/
/**
* Plays a song
* @param {Song} song - The {@link Song} to be played
*/
function play (song) {
}
```
See: http://usejsdoc.org/tags-typedef.html
## Renaming
```js
/*
* @alias Foo.bar
* @name Foo.bar
*/
```
Prefer `alias` over `name`. See: http://usejsdoc.org/tags-alias.html

View File

@ -53,48 +53,71 @@ expect(target).to eq 1
expect(target).not_to eq 1 expect(target).not_to eq 1
``` ```
### Numeric
```rb ```rb
# Numeric expect(5).to be < 6
be < 6 expect(5).to == 5
== 5 expect(5).to equal value
equal value expect(5).to be_between(1, 10)
be_between(1, 10) expect(5).to be_within(0.05).of value
be_within(0.05).of value ```
be value ### Comparison
satisfy {|arg| ...}
predicate [optional args]
match regexp
be_an_instance_of <class> ```rb
be_a_kind_of <class> expect(x).to be value
expect(x).to satisfy { |arg| ... }
expect(x).to match /regexp/
```
respond_to <symbol> ### Predicate
# Control flow ```rb
raise_error expect(x).to be_zero # FixNum#zero?
raise_error(<exception> [, message]) expect(x).to be_empty # Array#empty?
expect(x).to have_key # Hash#has_key?
```
throw <symbol> ### Objects
# Enumerables/arrays ```rb
include <object> expect(obj).to be_an_instance_of MyClass
expect(obj).to be_a_kind_of MyClass
expect(obj).to respond_to :save!
```
have(<number>).things ### Control flow
have_at_least(<number>).things
have_at_most(<number>).things
have(<number>).errors_on(:field) ```rb
expect { user.save! }.to raise_error
expect { user.save! }.to raise_error(ExceptionName, /msg/)
expect { user.save! }.to throw :symbol
```
# Change ### Enumerables/arrays
change(instance, method).from(number).to(number)
# proc.should <=> expect(&proc).to ```rb
expect { thing.approve! }.to change(thing, :status). expect(list).to include(<object>)
from(Status::AWAITING_APPROVAL).
to(Status::APPROVED)
expect { thing.destroy }.to change(Thing, :count).by(-1) expect(list).to have(1).things
expect(list).to have_at_least(2).things
expect(list).to have_at_most(3).things
expect(list).to have(2).errors_on(:field)
```
### Change
```rb
expect { thing.approve! }.to \
change(thing, :status)
.from(Status::AWAITING_APPROVAL)
.to(Status::APPROVED)
expect { thing.destroy }.to \
change(Thing, :count)
.by(-1)
``` ```
### Double ### Double