Skip to content

Commit

Permalink
Fix: allow and_error matcher to use RSpec matcher as and_value does (#51
Browse files Browse the repository at this point in the history
)

* Fix: allow and_error matcher to use RSpec matcher as and_value does

* Add PR to Changelog

* Add example to README.md
  • Loading branch information
bvicenzo authored Jul 18, 2024
1 parent 0589a18 commit a791ee4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Drop Support to Ruby 2.6 and 2.7
- Add Support to Ruby 3.2 and 3.3
- Changed and_error to use a matcher instead of equality comparation #51

## 0.3.0
### Added
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ require 'f_service/rspec'

### Mocking a result

```
```rb
mock_service(Uer::Create)
# => Mocks a successful result with all values nil

Expand Down Expand Up @@ -313,6 +313,8 @@ expect(User::Create.(name: 'Joe')).to have_succeed_with(:created).and_value(an_i
expect(User::Create.(name: nil)).to have_failed_with(:invalid_attributes)

expect(User::Create.(name: nil)).to have_failed_with(:invalid_attributes).and_error({ name: ["can't be blank"] })

expect(User::Create.(name: nil)).to have_failed_with(:invalid_attributes).and_error(a_hash_including(name: ["can't be blank"]))
```

## API Docs
Expand Down
2 changes: 1 addition & 1 deletion lib/f_service/rspec/support/matchers/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
match do |actual|
matched = actual.is_a?(FService::Result::Failure) && actual.types == expected_types

matched &&= actual.error == @expected_error if defined?(@expected_error)
matched &&= values_match?(@expected_error, actual.error) if defined?(@expected_error)

matched
end
Expand Down

0 comments on commit a791ee4

Please sign in to comment.