Skip to content

Commit

Permalink
Add include_graphql_error RSpec matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaiOnSoftware committed Jan 30, 2024
1 parent e69081b commit 1b71db7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

_none_

## 3.0.1 (2024-01-30)

* Add `include_graphql_error` RSpec matcher

## 3.0.0 (2024-01-30)

**Changes**
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Help Nulogy applications be compliant with the [Standard on Error-handling in Gr
Add this line to your application's Gemfile:

```ruby
gem "nulogy_graphql_api", "2.1.0"
gem "nulogy_graphql_api", "3.0.1"
```

And then execute:
Expand Down Expand Up @@ -253,9 +253,7 @@ end

#### Custom matchers

These are the custom matchers available:

`have_graphql_data` for checking the response `data`
Use `have_graphql_data` for checking the response `data`.

```ruby
expect(response).to have_graphql_data(
Expand All @@ -265,12 +263,20 @@ expect(response).to have_graphql_data(
)
```

`have_graphql_error` for checking the response `errors`
Use `have_graphql_error` for matching exactly on the response `errors`. <br/>
The match succeeds when the `errors` array contains a single entry with the specified message.

```ruby
expect(response).to have_graphql_error("Error message")
```

Use `include_graphql_error` for matching inclusively on the response `errors`. <br/>
The match succeeds when the `errors` array includes an entry with the specified message.

```ruby
expect(response).to include_graphql_error("Error message")
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
8 changes: 8 additions & 0 deletions lib/nulogy_graphql_api/rspec/graphql_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,13 @@ module GraphqlMatchers
})
end
end

RSpec::Matchers.define :include_graphql_error do |message|
match do |actual_response|
expect(actual_response.fetch(:errors, nil)).to include(a_hash_including(
message: include(message)
))
end
end
end
end
2 changes: 1 addition & 1 deletion lib/nulogy_graphql_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NulogyGraphqlApi
VERSION = "3.0.0"
VERSION = "3.0.1"
end

0 comments on commit 1b71db7

Please sign in to comment.