/usr/share/doc/ruby-rspec-expectations/features/built_in_matchers/all.feature is in ruby-rspec-expectations 3.4.0c3e0m1s1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | Feature: `all` matcher
Use the `all` matcher to specify that a collection's objects all pass an expected matcher. This works on any enumerable object.
```ruby
expect([1, 3, 5]).to all( be_odd )
expect([1, 3, 5]).to all( be_an(Integer) )
expect([1, 3, 5]).to all( be < 10 )
expect([1, 3, 4]).to all( be_odd ) # fails
```
The matcher also supports compound matchers:
```ruby
expect([1, 3, 5]).to all( be_odd.and be < 10 )
expect([1, 4, 21]).to all( be_odd.or be < 10 )
```
If you are looking for "any" member of a collection that passes an expectation, look at the `include`-matcher.
Scenario: array usage
Given a file named "array_all_matcher_spec.rb" with:
"""ruby
RSpec.describe [1, 3, 5] do
it { is_expected.to all( be_odd ) }
it { is_expected.to all( be_an(Integer) ) }
it { is_expected.to all( be < 10 ) }
# deliberate failures
it { is_expected.to all( be_even ) }
it { is_expected.to all( be_a(String) ) }
it { is_expected.to all( be > 2 ) }
end
"""
When I run `rspec array_all_matcher_spec.rb`
Then the output should contain all of these:
| 6 examples, 3 failures |
| expected [1, 3, 5] to all be even |
| expected [1, 3, 5] to all be a kind of String |
| expected [1, 3, 5] to all be > 2 |
Scenario: compound matcher usage
Given a file named "compound_all_matcher_spec.rb" with:
"""ruby
RSpec.describe ['anything', 'everything', 'something'] do
it { is_expected.to all( be_a(String).and include("thing") ) }
it { is_expected.to all( be_a(String).and end_with("g") ) }
it { is_expected.to all( start_with("s").or include("y") ) }
# deliberate failures
it { is_expected.to all( include("foo").and include("bar") ) }
it { is_expected.to all( be_a(String).and start_with("a") ) }
it { is_expected.to all( start_with("a").or include("z") ) }
end
"""
When I run `rspec compound_all_matcher_spec.rb`
Then the output should contain all of these:
| 6 examples, 3 failures |
| expected ["anything", "everything", "something"] to all include "foo" and include "bar" |
| expected ["anything", "everything", "something"] to all be a kind of String and start with "a" |
| expected ["anything", "everything", "something"] to all start with "a" or include "z" |
|