Skip to content

Commit 3f46828

Browse files
committed
update README
1 parent ef28075 commit 3f46828

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

README.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@
22

33
This allows you to get detailed error messages on exactly where your heavily nested hashes differ
44

5-
## Installation
5+
### Example
6+
```ruby
7+
actual = {b: {c: 1, [{d: {e: 'actual_value'}}]}}
8+
expected = {b: {c: 5, [{d: {e: 'expected_value'}}]}}
9+
10+
aggregate_failures do
11+
expect_deep_matching(actual, expected)
12+
end
13+
```
614

7-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
15+
#### Fails with
816

9-
Install the gem and add to the application's Gemfile by executing:
17+
```
18+
Got 2 failures from failure aggregation block
19+
1) Expected nested hash key at 'b.c'
20+
to eq
21+
# 5,
22+
but got
23+
1
24+
2) Expected nested hash key at 'b.[0].d.e'
25+
to eq
26+
# 'expected_value',
27+
but got
28+
'actual_value'
29+
```
1030

11-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
31+
Note, only keys in the expected hash are checked. If the actual hash has extra keys, they are ignored.
32+
In this way it acts somewhat like `expect(actual).to match(hash_including(expected))`
1233

13-
If bundler is not being used to manage dependencies, install the gem by executing:
34+
## Installation
1435

15-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
36+
```
37+
gem 'deep_matching'
38+
```
1639

1740
## Usage
1841

spec/deep_matching_spec.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
expect_failure(actual, expected, path: 'b.c.2.d', expected_value: '"expected"', got: '"actual"')
4343
end
4444

45-
it 'produces multiple failure messages' do
45+
it 'produces multiple failure messages when used with aggregate_failures' do
4646
actual = {a: 1, b: {c: [1, 2, {d: 'actual' }]}}
4747
expected = {a: 2, b: {c: [1, 2, {d: 'expected'}]}}
4848

@@ -74,14 +74,6 @@
7474
FAILURE
7575
end
7676

77-
def expect_in_message(message, expected)
78-
expect(message).to include(expected.chomp.gsub(/^\s+/, ''))
79-
end
80-
81-
def expect_success(actual, expected)
82-
expect_deep_matching(actual, expected)
83-
end
84-
8577
def expect_multiple_failures(actual, expected)
8678
@raised_messages = []
8779

@@ -94,6 +86,15 @@ def expect_multiple_failures(actual, expected)
9486
@raised_messages << e.message
9587
end
9688

89+
90+
def expect_in_message(message, expected)
91+
expect(message).to include(expected.chomp.gsub(/^\s+/, ''))
92+
end
93+
94+
def expect_success(actual, expected)
95+
expect_deep_matching(actual, expected)
96+
end
97+
9798
def expect_failure(actual, expected, expected_failure)
9899
expected_value = expected_failure[:expected_value]
99100
got = expected_failure[:got]

0 commit comments

Comments
 (0)