File: README.md

package info (click to toggle)
ruby-rspec-expectations 2.14.2-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 920 kB
  • sloc: ruby: 8,202; makefile: 4
file content (90 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Built-in Matchers

rspec-expectations ships with a number of built-in matchers.
Each matcher can be used with `expect(..).to` or `expect(..).not_to` to define
positive and negative expectations respectively on an object. Most matchers can
also be accessed using the `(...).should` and `(...).should_not` syntax, see
[using should syntax](https://github.com/rspec/rspec-expectations/blob/master/Should.md)
for why we recommend using `expect`.

e.g.

    expect(result).to   eq(3)
    expect(list).not_to be_empty
    pi.should be > 3

## Object identity

    expect(actual).to be(expected) # passes if actual.equal?(expected)

## Object equivalence

    expect(actual).to eq(expected) # passes if actual == expected

## Optional APIs for identity/equivalence

    expect(actual).to eql(expected)   # passes if actual.eql?(expected)
    expect(actual).to equal(expected) # passes if actual.equal?(expected)

    # NOTE: `expect` does not support `==` matcher.

## Comparisons

    expect(actual).to be >  expected
    expect(actual).to be >= expected
    expect(actual).to be <= expected
    expect(actual).to be <  expected
    expect(actual).to match(/expression/)
    expect(actual).to be_within(delta).of(expected)

    # NOTE: `expect` does not support `=~` matcher.

## Types/classes

    expect(actual).to be_instance_of(expected)
    expect(actual).to be_kind_of(expected)

## Truthiness and existentialism

    expect(actual).to be_true  # passes if actual is truthy (not nil or false)
    expect(actual).to be_false # passes if actual is falsy (nil or false)
    expect(actual).to be_nil   # passes if actual is nil
    expect(actual).to be       # passes if actual is truthy (not nil or false)

## Expecting errors

    expect { ... }.to raise_error
    expect { ... }.to raise_error(ErrorClass)
    expect { ... }.to raise_error("message")
    expect { ... }.to raise_error(ErrorClass, "message")

## Expecting throws

    expect { ... }.to throw_symbol
    expect { ... }.to throw_symbol(:symbol)
    expect { ... }.to throw_symbol(:symbol, 'value')

## Predicate matchers

    expect(actual).to be_xxx         # passes if actual.xxx?
    expect(actual).to have_xxx(:arg) # passes if actual.has_xxx?(:arg)

### Examples

    expect([]).to      be_empty
    expect(:a => 1).to have_key(:a)

## Collection membership

    expect(actual).to include(expected)

### Examples

    expect([1,2,3]).to       include(1)
    expect([1,2,3]).to       include(1, 2)
    expect(:a => 'b').to     include(:a => 'b')
    expect("this string").to include("is str")

## Ranges (1.9 only)

    expect(1..10).to cover(3)