Skip to content

Commit

Permalink
Merge pull request #23 from nulogy/add-include-graphql-error-matcher
Browse files Browse the repository at this point in the history
add include graphql error matcher
  • Loading branch information
github-actions[bot] authored Jan 30, 2024
2 parents ee79b02 + 1b71db7 commit 762a303
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.1.4
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.1.4
4 changes: 0 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
appraise "rails-6" do
gem "rails", "6.0.3.7"
end

appraise "rails-6-1" do
gem "rails", "6.1.4"
end
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

_none_

## 3.0.1 (2024-01-30)

* Add `include_graphql_error` RSpec matcher

## 3.0.0 (2024-01-30)

**Changes**
* **(Breaking)** Drop support for Rails 6.0
* **(Breaking)** Drop support for Ruby 2.7

## 2.2.0 (2024-01-15)

**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
7 changes: 0 additions & 7 deletions gemfiles/rails_6.gemfile

This file was deleted.

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 = "2.2.0"
VERSION = "3.0.1"
end
4 changes: 2 additions & 2 deletions nulogy_graphql_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
"rubygems_mfa_required" => "true"
}

spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "graphql", "~> 2"
spec.add_dependency "graphql-schema_comparator", "~> 1.2"
spec.add_dependency "rails", ">= 6.0", "< 8.0"
spec.add_dependency "rails", ">= 6.1", "< 8.0"
spec.add_dependency "rainbow", "~> 3.0"

spec.add_development_dependency "appraisal", "~> 2.5"
Expand Down

0 comments on commit 762a303

Please sign in to comment.