rspec-graphql_matchers 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64ee8b20fc5bbe24c5526a14923eba402e023d52
4
+ data.tar.gz: 2203f40b9379eecc78296e0637bb8033e91daa5b
5
+ SHA512:
6
+ metadata.gz: 85b11832795d76ca55a19c7fe62c9cc60fa5560781031dfac192ee16779624366da10e15d1178d3e7fda5c6779804ad8aa40749864236f9c4a157697e6e54a4d
7
+ data.tar.gz: 4770e6cbeabe74e48b36ed621fbe494ae37195ae5e0cc766a639a13b660173ab44ae5261cda8d9fd45578cfb29531b8a36caed301bea118cc3bfbfbccf89822a
data/.codeclimate.yml ADDED
@@ -0,0 +1,31 @@
1
+ ---
2
+ engines:
3
+ bundler-audit:
4
+ enabled: true
5
+ duplication:
6
+ enabled: true
7
+ config:
8
+ languages:
9
+ - ruby
10
+ - javascript
11
+ - python
12
+ - php
13
+ fixme:
14
+ enabled: true
15
+ rubocop:
16
+ enabled: true
17
+ ratings:
18
+ paths:
19
+ - Gemfile.lock
20
+ - "**.inc"
21
+ - "**.js"
22
+ - "**.jsx"
23
+ - "**.module"
24
+ - "**.php"
25
+ - "**.py"
26
+ - "**.rb"
27
+ exclude_paths:
28
+ - spec/
29
+ - rspec-graphql_matchers.gemspec
30
+ - bin/
31
+ - Rakefile
data/.editorconfig ADDED
@@ -0,0 +1,18 @@
1
+ # EditorConfig help us maintain consistent coding style between different editors.
2
+ #
3
+ # EditorConfig
4
+ # http://editorconfig.org
5
+ #
6
+ root = true
7
+
8
+ [*]
9
+ indent_style = space
10
+ indent_size = 2
11
+ end_of_line = lf
12
+ charset = utf-8
13
+ trim_trailing_whitespace = true
14
+ insert_final_newline = true
15
+
16
+ [*.md]
17
+ trim_trailing_whitespace = false
18
+ indent_size = 4
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/ClassAndModuleChildren:
5
+ EnforcedStyle: compact
6
+
7
+ Style/MultilineMethodCallIndentation:
8
+ EnforcedStyle: indented
9
+
10
+ Style/AlignParameters:
11
+ EnforcedStyle: with_fixed_indentation
12
+
13
+ Style/ClassAndModuleChildren:
14
+ Enabled: false
15
+
16
+ Style/SpaceBeforeFirstArg:
17
+ Include:
18
+ - db/migrate/*.rb
19
+ Enabled: false
20
+
21
+ Style/Lambda:
22
+ Enabled: false
23
+
24
+ Metrics/LineLength:
25
+ Max: 80
26
+
27
+ Metrics/MethodLength:
28
+ Max: 15
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.3
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at gb.samuel@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-graphql_matchers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Samuel Brandão
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # Rspec::GraphqlMatchers
2
+
3
+ Convenient rspec matchers for testing your (GraphQL)[https://github.com/rmosolgo/graphql-ruby] API/Schema.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem 'rspec-graphql_matchers'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The two matchers currently supported are:
14
+ - be_of_type(a_graphql_type_identifier)
15
+ - accept_arguments(hash_of_arg_names_and_type_identifiers)
16
+
17
+ Where a type identifier is either:
18
+ - A GraphQL type object (ex: `types.String`, `!types.Int`, `types[types.Int]`)
19
+ - A String representation of a type: `"String!"`, `"Int!"`, `"[String]!"`
20
+
21
+ ## Examples
22
+
23
+ Given a GraphQL type defined as such
24
+
25
+ ```ruby
26
+
27
+ PostType = GraphQL::ObjectType.define do
28
+ name "Post"
29
+ description "A blog post"
30
+
31
+ field :id, !types.ID
32
+
33
+ field :comments, !types[types.String]
34
+
35
+ field :subposts, PostType do
36
+ type !PostType
37
+
38
+ argument :filter, types.String
39
+ argument :id, types.ID
40
+ end
41
+ end
42
+ ```
43
+
44
+ ### 1) Test the field types with `be_of_type` matcher:
45
+
46
+ ```ruby
47
+ describe PostType do
48
+ describe 'id' do
49
+ subject { PostType.fields['id'] }
50
+
51
+ # These will match
52
+ it { is_expected.to be_of_type('ID!') }
53
+
54
+ # While 'Float!' will not match
55
+ it { is_expected.not_to be_of_type('Float!') }
56
+ end
57
+
58
+ describe 'subposts' do
59
+ subject { PostType.fields['subposts'] }
60
+
61
+ # You can use your type object directly when building expectations
62
+ it 'has type PostType' do
63
+ expect(subject).to be_of_type(!PostType)
64
+ end
65
+
66
+ # Or as usual, a literal String
67
+ it { is_expected.to be_of_type('Post!') }
68
+ end
69
+ end
70
+ ```
71
+
72
+ Keep in mind that when using strings as type expectation you have to use the
73
+ type name (`Post`) and not the constant name (`PostType`).
74
+
75
+ Using your type objects directly has the advantage that if you
76
+ decide to rename the type your specs won't break, as they would had you
77
+ hardcoded the type name as a String.
78
+
79
+ You can also use the built-in GraphQL scalar types:
80
+
81
+
82
+ ```ruby
83
+ # ensure you have the GraphQL type definer available in your tests
84
+ types = GraphQL::Define::TypeDefiner.instance
85
+
86
+ describe PostType do
87
+ describe 'comments' do
88
+ subject { PostType.fields['comments'] }
89
+ it { is_expected.to be_of_type(!types[types.String]) }
90
+ it { is_expected.to be_of_type('[String]!') }
91
+ end
92
+ end
93
+ ```
94
+
95
+ Having to define `types` everywhere is quite annoying. If you prefer, you can
96
+ just `include RSpec::GraphqlMatchers::TypesHelper` once
97
+ (for example in your `spec_helper.rb`, but not within a `RSpec.configure` block)
98
+ and the `types` shortcut will be available globally (ouch!) for your tests.
99
+ Use at your own risk.
100
+
101
+ ### 2) Test the arguments accepted by a field with `accept_arguments` matcher:
102
+
103
+ Testing arguments use the `accept_arguments` matcher passing a hash where
104
+ keys represent the attribute name and values respresent the attribute type.
105
+
106
+ ```ruby
107
+ describe PostType do
108
+ describe 'subposts' do
109
+ subject { PostType.fields['subposts'] }
110
+
111
+ let(:a_whole_bunch_of_args) do
112
+ { filter: 'String', id: types.Int, pippo: 'Float', posts: PostType }
113
+ end
114
+
115
+ it 'accepts a filter and an id argument, of types String and ID' do
116
+ expect(subject).to accept_arguments(filter: types.String, id: types.ID)
117
+ end
118
+
119
+ # You can also test if a field does not accept args. Not quite useful :D.
120
+ it { is_expected.not_to accept_arguments(a_whole_bunch_of_args) }
121
+ end
122
+ end
123
+ ```
124
+ The spec will pass only if all attributes/types specified in the hash are
125
+ defined on the field. Type specification follows the same rules from
126
+ `be_of_type` matcher.
127
+
128
+ For better fluency, `accept_arguments` is always available in singular form, as
129
+ `accept_argument`.
130
+
131
+ ## Contributing
132
+
133
+ - Send Bug reports, suggestions or any general
134
+ question through the [Issue tracker](https://github.com/khamusa/rspec-graphql_matchers/issues).
135
+ Think of another matcher that could be useful? This is the place to ask, or...
136
+ - Pull requests are welcome through the usual procedure: fork the project,
137
+ commit your changes and open the [PR](https://github.com/khamusa/rspec-graphql_matchers/pulls).
138
+
139
+ This project is intended to be a safe, welcoming space for collaboration, and
140
+ contributors are expected to adhere to the
141
+ [Contributor Covenant](http://contributor-covenant.org) code of conduct.
142
+
143
+ ## License
144
+
145
+ The gem is available as open source under the terms of the
146
+ [MIT License](http://opensource.org/licenses/MIT).
147
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec/graphql_matchers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ module RSpec
2
+ module GraphqlMatchers
3
+ class AcceptArguments
4
+ attr_reader :actual_field, :expected_args
5
+
6
+ def initialize(expected_args)
7
+ @expected_args = expected_args
8
+ end
9
+
10
+ def matches?(actual_field)
11
+ @actual_field = actual_field
12
+
13
+ @expected_args.all? do |arg_name, arg_type|
14
+ matches_argument?(arg_name, arg_type)
15
+ end
16
+ end
17
+
18
+ def failure_message
19
+ "expected field '#{field_name(actual_field)}' to accept arguments "\
20
+ "#{describe_arguments(expected_args)}"
21
+ end
22
+
23
+ def description
24
+ "accept arguments #{describe_arguments(expected_args)}"
25
+ end
26
+
27
+ private
28
+
29
+ def matches_argument?(arg_name, arg_type)
30
+ actual_arg = actual_field.arguments[arg_name.to_s]
31
+ actual_arg && actual_arg.type.to_s == arg_type.to_s
32
+ end
33
+
34
+ def describe_arguments(what_args)
35
+ what_args.sort.map do |arg_name, arg_type|
36
+ "#{arg_name}(#{arg_type})"
37
+ end.join(', ')
38
+ end
39
+
40
+ def field_name(field)
41
+ field.respond_to?(:name) && field.name || field.inspect
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ module RSpec
2
+ module GraphqlMatchers
3
+ class BeOfType
4
+ attr_reader :sample, :expected
5
+
6
+ def initialize(expected)
7
+ @expected = expected
8
+ end
9
+
10
+ def matches?(actual_sample)
11
+ @sample = actual_sample
12
+ sample.type.to_s == @expected.to_s
13
+ end
14
+
15
+ def failure_message
16
+ "expected field '#{field_name(sample)}' to be of type '#{expected}', " \
17
+ "but it was '#{sample.type}'"
18
+ end
19
+
20
+ def description
21
+ "be of type '#{expected}'"
22
+ end
23
+
24
+ private
25
+
26
+ def field_name(field)
27
+ field.respond_to?(:name) && field.name || field.inspect
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspec/matchers'
2
+ require 'rspec/graphql_matchers/be_of_type'
3
+ require 'rspec/graphql_matchers/accept_arguments'
4
+
5
+ module RSpec
6
+ module Matchers
7
+ def be_of_type(expected)
8
+ RSpec::GraphqlMatchers::BeOfType.new(expected)
9
+ end
10
+
11
+ def accept_arguments(expected_args)
12
+ RSpec::GraphqlMatchers::AcceptArguments.new(expected_args)
13
+ end
14
+
15
+ alias accept_argument accept_arguments
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module RSpec
2
+ module GraphqlMatchers
3
+ module TypesHelper
4
+ def types
5
+ GraphQL::Define::TypeDefiner.instance
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module GraphqlMatchers
3
+ VERSION = '0.2.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec/graphql_matchers/version'
2
+ require 'rspec/graphql_matchers/matchers'
3
+ require 'rspec/graphql_matchers/types_helper'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/graphql_matchers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rspec-graphql_matchers'
8
+ spec.version = Rspec::GraphqlMatchers::VERSION
9
+ spec.authors = ['Samuel Brandão']
10
+ spec.email = ['gb.samuel@gmail.com']
11
+
12
+ spec.summary = 'Collection of rspec matchers to test your graphQL api schema.'
13
+ spec.homepage = 'https://github.com/khamusa/rspec-graphql_matchers'
14
+ spec.license = 'MIT'
15
+
16
+ # raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'graphql', '>= 0.9', '< 1'
24
+ spec.add_development_dependency 'bundler', '~> 1.12'
25
+ spec.add_development_dependency 'rubocop', '~> 0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'pry', '~> 0'
28
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-graphql_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Brandão
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: graphql
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.12'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.12'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rubocop
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description:
90
+ email:
91
+ - gb.samuel@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".codeclimate.yml"
97
+ - ".editorconfig"
98
+ - ".gitignore"
99
+ - ".rspec"
100
+ - ".rubocop.yml"
101
+ - ".travis.yml"
102
+ - CODE_OF_CONDUCT.md
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/console
108
+ - bin/setup
109
+ - lib/rspec/graphql_matchers.rb
110
+ - lib/rspec/graphql_matchers/accept_arguments.rb
111
+ - lib/rspec/graphql_matchers/be_of_type.rb
112
+ - lib/rspec/graphql_matchers/matchers.rb
113
+ - lib/rspec/graphql_matchers/types_helper.rb
114
+ - lib/rspec/graphql_matchers/version.rb
115
+ - rspec-graphql_matchers.gemspec
116
+ homepage: https://github.com/khamusa/rspec-graphql_matchers
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.0
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Collection of rspec matchers to test your graphQL api schema.
140
+ test_files: []
141
+ has_rdoc: