Skip to content

Commit a7c7744

Browse files
committed
More readthedocs documentation
1 parent 6a331e3 commit a7c7744

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ C++Spec is a behavior-driven development library with an RSpec-inspired DSL.
66

77
## Overview ##
88

9+
C++Spec is a behavior-driven development library for C++ with an RSpec-inspired DSL. Designed with ease of use and rapid prototyping in mind, C++Spec offers an alternative to traditional testing libraries and frameworks.
10+
11+
Also see the [official GitHub pages site](http://toroidal-code.github.io/cppspec/) for more
12+
information.
913

1014
## Installing ##
1115

16+
Either run `git clone https://github.com/toroidal-code/cppspec.git` or download the collated header
17+
file (if it is available). You can also download a ZIP version of the repo.
1218

19+
If you want to manually generate the collated `cppspec.hpp`, you can download the ccollate tool [here](https://raw.githubusercontent.com/toroidal-code/ccollate/master/ccollate.rb) and then run `./ccollate.rb` in the toplevel directory of the C++Spec repo.

docs/syntax/expect.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Expect
2+
3+
Expectations are the primary focus of C++Spec, allowing clean, readable tests without falling
4+
back on assertions.
5+
6+
Expectations have two parts, the "actual" value, and the "expected" value.
7+
8+
```c++
9+
auto x = 2;
10+
expect(x).to_equal(2);
11+
// ^ ^
12+
// actual expected
13+
```
14+
15+
The `expect` half references whatever is being tested (the "actual" result of the test), while the
16+
matcher references what the value _should_ be (the "expected" value of the test).
17+
18+
## Values
19+
20+
The standard usage of an `expect` is to reference a variable or value to test.
21+
22+
```c++
23+
Something some_thing();
24+
25+
expect(some_thing.some_method()).to_be_true();
26+
```
27+
28+
## Lambdas
29+
30+
Expectations are also to contain lambdas that return objects or throw exceptions.
31+
32+
```c++
33+
expect([] { return 2; }).to_equal(2);
34+
expect([] { throw std::exception; }).to_throw<std::exception>();
35+
```
36+
37+
This allows creating delayed "thunks" that can be created earlier and then passed to the
38+
`Expectation`.
39+
40+
```c++
41+
auto val = [] { return 5; };
42+
expect(val).to_equal(5);
43+
```

docs/syntax/it.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,30 @@
11
# It
22
`it`s are the examples of the spec. A `Description` holds a group of `it`s, where each `it` has at least one expectation.
3+
4+
An `it` has the form of
5+
6+
```c++
7+
it("description string", _ {...})
8+
```
9+
10+
An `it` can also have an implicit description that is generated by the contained expectation
11+
12+
```c++
13+
it(_{...})
14+
```
15+
16+
!!! important
17+
18+
Take note of the `_`. This is used whenever you write an `it`, similar to `$` for `describe`.
19+
20+
21+
Each `it` is run as part of the containing parent `Description`, whether that be the toplevel
22+
`describe` or an `explain`.
23+
24+
So for example,
25+
26+
```c++
27+
describe an_example_it("An example of an it", $ {
28+
it("looks like this", {...});
29+
});
30+
```

docs/syntax/let.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
# Let
3+
4+
A `let` introduces a memoized local variable inside of a `Description`. This is best shown in an
5+
example:
6+
7+
```c++
8+
int _count = 0;
9+
describe let_spec("let", $ {
10+
let(count, [&]{ return ++_count ;});
11+
12+
it("memoizes the value", _ {
13+
expect(count).to_equal(1);
14+
expect(count).to_equal(1);
15+
});
16+
17+
it("is not cached across examples", _ {
18+
expect(count).to_equal(2);
19+
});
20+
});
21+
```
22+
23+
As shown, `let`s allow setting a mutating variable before each `it`.

0 commit comments

Comments
 (0)