Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1452 from rspec/fix-documentation-indentation
Browse files Browse the repository at this point in the history
Fix documentation indentation
  • Loading branch information
JonRowe authored Mar 18, 2024
2 parents 21ab125 + a884b05 commit e859d35
Show file tree
Hide file tree
Showing 27 changed files with 247 additions and 233 deletions.
28 changes: 18 additions & 10 deletions DEV-README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
## Set up the dev environment

git clone https://github.com/rspec/rspec-expectations.git
cd rspec-expectations
gem install bundler
bundle install
```shell
git clone https://github.com/rspec/rspec-expectations.git
cd rspec-expectations
gem install bundler
bundle install
```

Now you should be able to run any of:

rake
rake spec
rake cucumber
```shell
rake
rake spec
rake cucumber
```

Or, if you prefer to use the rspec and cucumber commands directly, you can either:

bundle exec rspec
```shell
bundle exec rspec
```

Or ...

bundle install --binstubs
bin/rspec
```shell
bundle install --binstubs
bin/rspec
```

## Customize the dev environment

Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ If you want to use rspec-expectations with rspec, just install the rspec gem
and RubyGems will also install rspec-expectations for you (along with
rspec-core and rspec-mocks):

gem install rspec
```shell
gem install rspec
```

Want to run against the `main` branch? You'll need to include the dependent
RSpec repos as well. Add the following to your `Gemfile`:
Expand All @@ -27,7 +29,9 @@ end
If you want to use rspec-expectations with another tool, like Test::Unit,
Minitest, or Cucumber, you can install it directly:

gem install rspec-expectations
```shell
gem install rspec-expectations
```

## Contributing

Expand Down Expand Up @@ -67,8 +71,10 @@ The `describe` and `it` methods come from rspec-core. The `Order`, `LineItem`,
expresses an expected outcome. If `order.total == Money.new(5.55, :USD)`, then
the example passes. If not, it fails with a message like:

expected: #<Money @value=5.55 @currency=:USD>
got: #<Money @value=1.11 @currency=:USD>
```
expected: #<Money @value=5.55 @currency=:USD>
got: #<Money @value=1.11 @currency=:USD>
```

## Built-in matchers

Expand Down
30 changes: 15 additions & 15 deletions features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
rspec-expectations is used to define expected outcomes.

```ruby
RSpec.describe Account do
it "has a balance of zero when first created" do
expect(Account.new.balance).to eq(Money.new(0))
end
end
RSpec.describe Account do
it "has a balance of zero when first created" do
expect(Account.new.balance).to eq(Money.new(0))
end
end
```

## Basic structure

The basic structure of an rspec expectation is:

```ruby
expect(actual).to matcher(expected)
expect(actual).not_to matcher(expected)
expect(actual).to matcher(expected)
expect(actual).not_to matcher(expected)
```

Note: You can also use `expect(..).to_not` instead of `expect(..).not_to`.
Expand All @@ -25,26 +25,26 @@ Note: You can also use `expect(..).to_not` instead of `expect(..).not_to`.
#### Examples

```ruby
expect(5).to eq(5)
expect(5).not_to eq(4)
expect(5).to eq(5)
expect(5).not_to eq(4)
```

## What is a matcher?

A matcher is any object that responds to the following methods:

```ruby
matches?(actual)
failure_message
matches?(actual)
failure_message
```

These methods are also part of the matcher protocol, but are optional:

```ruby
does_not_match?(actual)
failure_message_when_negated
description
supports_block_expectations?
does_not_match?(actual)
failure_message_when_negated
description
supports_block_expectations?
```

RSpec ships with a number of built-in matchers and a DSL for writing custom
Expand Down
142 changes: 71 additions & 71 deletions features/built_in_matchers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,172 +8,172 @@ respectively on an object. Most matchers can also be accessed using the `(...).s
e.g.

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

## Object identity

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

## Object equivalence

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

## Optional APIs for identity/equivalence

```ruby
expect(actual).to eql(expected) # passes if actual.eql?(expected)
expect(actual).to equal(expected) # passes if actual.equal?(expected)
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.
# NOTE: `expect` does not support `==` matcher.
```

## Comparisons

```ruby
expect(actual).to be > expected
expect(actual).to be >= expected
expect(actual).to be <= expected
expect(actual).to be < expected
expect(actual).to be_between(minimum, maximum).inclusive
expect(actual).to be_between(minimum, maximum).exclusive
expect(actual).to match(/expression/)
expect(actual).to be_within(delta).of(expected)
expect(actual).to start_with expected
expect(actual).to end_with expected
expect(actual).to be > expected
expect(actual).to be >= expected
expect(actual).to be <= expected
expect(actual).to be < expected
expect(actual).to be_between(minimum, maximum).inclusive
expect(actual).to be_between(minimum, maximum).exclusive
expect(actual).to match(/expression/)
expect(actual).to be_within(delta).of(expected)
expect(actual).to start_with expected
expect(actual).to end_with expected

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

## Types/classes/response

```ruby
expect(actual).to be_instance_of(expected)
expect(actual).to be_kind_of(expected)
expect(actual).to respond_to(expected)
expect(actual).to be_instance_of(expected)
expect(actual).to be_kind_of(expected)
expect(actual).to respond_to(expected)
```

## Truthiness and existentialism

```ruby
expect(actual).to be_truthy # passes if actual is truthy (not nil or false)
expect(actual).to be true # passes if actual == true
expect(actual).to be_falsey # passes if actual is falsy (nil or false)
expect(actual).to be false # passes if actual == false
expect(actual).to be_nil # passes if actual is nil
expect(actual).to exist # passes if actual.exist? and/or actual.exists? are truthy
expect(actual).to exist(*args) # passes if actual.exist?(*args) and/or actual.exists?(*args) are truthy
expect(actual).to be_truthy # passes if actual is truthy (not nil or false)
expect(actual).to be true # passes if actual == true
expect(actual).to be_falsey # passes if actual is falsy (nil or false)
expect(actual).to be false # passes if actual == false
expect(actual).to be_nil # passes if actual is nil
expect(actual).to exist # passes if actual.exist? and/or actual.exists? are truthy
expect(actual).to exist(*args) # passes if actual.exist?(*args) and/or actual.exists?(*args) are truthy
```

## Expecting errors

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

## Expecting throws

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

## Predicate matchers

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

### Examples

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

## Collection membership

```ruby
expect(actual).to include(expected)
expect(array).to match_array(expected_array)
# ...which is the same as:
expect(array).to contain_exactly(individual, elements)
expect(actual).to include(expected)
expect(array).to match_array(expected_array)
# ...which is the same as:
expect(array).to contain_exactly(individual, elements)
```

### Examples

```ruby
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")
expect([1, 2, 3]).to contain_exactly(2, 1, 3)
expect([1, 2, 3]).to match_array([3, 2, 1])
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")
expect([1, 2, 3]).to contain_exactly(2, 1, 3)
expect([1, 2, 3]).to match_array([3, 2, 1])
```

## Ranges (1.9+ only)

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

## Change observation

```ruby
expect { object.action }.to change(object, :value).from(old).to(new)
expect { object.action }.to change(object, :value).by(delta)
expect { object.action }.to change(object, :value).by_at_least(minimum_delta)
expect { object.action }.to change(object, :value).by_at_most(maximum_delta)
expect { object.action }.to change(object, :value).from(old).to(new)
expect { object.action }.to change(object, :value).by(delta)
expect { object.action }.to change(object, :value).by_at_least(minimum_delta)
expect { object.action }.to change(object, :value).by_at_most(maximum_delta)
```

### Examples

```ruby
expect { a += 1 }.to change { a }.by(1)
expect { a += 3 }.to change { a }.from(2)
expect { a += 3 }.to change { a }.by_at_least(2)
expect { a += 1 }.to change { a }.by(1)
expect { a += 3 }.to change { a }.from(2)
expect { a += 3 }.to change { a }.by_at_least(2)
```

## Satisfy

```ruby
expect(actual).to satisfy { |value| value == expected }
expect(actual).to satisfy { |value| value == expected }
```

## Output capture

```ruby
expect { actual }.to output("some output").to_stdout
expect { actual }.to output("some error").to_stderr
expect { actual }.to output("some output").to_stdout
expect { actual }.to output("some error").to_stderr
```

## Block expectation

```ruby
expect { |b| object.action(&b) }.to yield_control
expect { |b| object.action(&b) }.to yield_with_no_args # only matches no args
expect { |b| object.action(&b) }.to yield_with_args # matches any args
expect { |b| object.action(&b) }.to yield_successive_args(*args) # matches args against multiple yields
expect { |b| object.action(&b) }.to yield_control
expect { |b| object.action(&b) }.to yield_with_no_args # only matches no args
expect { |b| object.action(&b) }.to yield_with_args # matches any args
expect { |b| object.action(&b) }.to yield_successive_args(*args) # matches args against multiple yields
```

### Examples

```ruby
expect { |b| User.transaction(&b) }.to yield_control
expect { |b| User.transaction(&b) }.to yield_with_no_args
expect { |b| 5.tap(&b) }.not_to yield_with_no_args # because it yields with `5`
expect { |b| 5.tap(&b) }.to yield_with_args(5) # because 5 == 5
expect { |b| 5.tap(&b) }.to yield_with_args(Integer) # because Integer === 5
expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
expect { |b| User.transaction(&b) }.to yield_control
expect { |b| User.transaction(&b) }.to yield_with_no_args
expect { |b| 5.tap(&b) }.not_to yield_with_no_args # because it yields with `5`
expect { |b| 5.tap(&b) }.to yield_with_args(5) # because 5 == 5
expect { |b| 5.tap(&b) }.to yield_with_args(Integer) # because Integer === 5
expect { |b| [1, 2, 3].each(&b) }.to yield_successive_args(1, 2, 3)
```
Loading

0 comments on commit e859d35

Please sign in to comment.