Update rspec
This commit is contained in:
parent
b0b9fd1fb5
commit
e61d3dfc57
58
flowtype.md
58
flowtype.md
|
@ -29,7 +29,13 @@ boolean
|
|||
mixed
|
||||
number
|
||||
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>
|
||||
Class<T>
|
||||
|
@ -37,6 +43,56 @@ Function
|
|||
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
|
||||
var myNumbers: Array<number> = [42]
|
||||
function foo(): any { return 42 }
|
||||
|
|
|
@ -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
|
83
rspec.md
83
rspec.md
|
@ -53,48 +53,71 @@ expect(target).to eq 1
|
|||
expect(target).not_to eq 1
|
||||
```
|
||||
|
||||
### Numeric
|
||||
|
||||
```rb
|
||||
# Numeric
|
||||
be < 6
|
||||
== 5
|
||||
equal value
|
||||
be_between(1, 10)
|
||||
be_within(0.05).of value
|
||||
expect(5).to be < 6
|
||||
expect(5).to == 5
|
||||
expect(5).to equal value
|
||||
expect(5).to be_between(1, 10)
|
||||
expect(5).to be_within(0.05).of value
|
||||
```
|
||||
|
||||
be value
|
||||
satisfy {|arg| ...}
|
||||
predicate [optional args]
|
||||
match regexp
|
||||
### Comparison
|
||||
|
||||
be_an_instance_of <class>
|
||||
be_a_kind_of <class>
|
||||
```rb
|
||||
expect(x).to be value
|
||||
expect(x).to satisfy { |arg| ... }
|
||||
expect(x).to match /regexp/
|
||||
```
|
||||
|
||||
respond_to <symbol>
|
||||
### Predicate
|
||||
|
||||
# Control flow
|
||||
raise_error
|
||||
raise_error(<exception> [, message])
|
||||
```rb
|
||||
expect(x).to be_zero # FixNum#zero?
|
||||
expect(x).to be_empty # Array#empty?
|
||||
expect(x).to have_key # Hash#has_key?
|
||||
```
|
||||
|
||||
throw <symbol>
|
||||
### Objects
|
||||
|
||||
# Enumerables/arrays
|
||||
include <object>
|
||||
```rb
|
||||
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
|
||||
have_at_least(<number>).things
|
||||
have_at_most(<number>).things
|
||||
### Control flow
|
||||
|
||||
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
|
||||
change(instance, method).from(number).to(number)
|
||||
### Enumerables/arrays
|
||||
|
||||
# proc.should <=> expect(&proc).to
|
||||
expect { thing.approve! }.to change(thing, :status).
|
||||
from(Status::AWAITING_APPROVAL).
|
||||
to(Status::APPROVED)
|
||||
```rb
|
||||
expect(list).to include(<object>)
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue