rspec-json_api 1.0.3 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92b47d5a7ba7e688c32ef7e4bd3a1ffea063990f651cbee54b7836d33415518c
4
- data.tar.gz: fcafadd473e00a3d61d87a14b672a94c3edefeacd754cac6aee8b4af6146fda7
3
+ metadata.gz: 926364f56a7d6913ba3ffc9f3247268727e8510cae6941aa6918f3101c3ecd27
4
+ data.tar.gz: 272e73fbd9562c005fdb1d3ac50e17cee84aa22e8e0383d0eb15d2d6606dd4c7
5
5
  SHA512:
6
- metadata.gz: d09a28d545718d0ca799b19ed75bf8e0837f37f52f1b4bdc7f4c503eba1a345773996c02a0a05d1515f6a21301030c84a7f539e3946feac26db001c4e61979a5
7
- data.tar.gz: d11562c3361aa0bb7d5f45fae5ded93c7233f30f851c44072cd9dd2e1c7f49bc4561ec2d96473bd586ef3d01a854ead62331b2d86d76a4b1601787dc918cb360
6
+ metadata.gz: 4be67b6d2146f39576b7766e7dc9eeda0ea7530f63e97e5cbb503424d3e95a0b7607e798f09acee83efeadde2e504df74b1dfcd3678082b518024c0d70917066
7
+ data.tar.gz: 4b723f4a170f36e563e7663c7e22286850ab60f376bd166db4a76476dc2faa3ca08fe055713419498657c5c52f4b6c609e3a8e27fba80c913ef5495ce0ed7932
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile CHANGED
@@ -9,5 +9,3 @@ gemspec
9
9
  gem "activesupport", "~> 6.1", ">= 6.1.4.1"
10
10
  gem "rake", "~> 13.0", ">= 13.0.6"
11
11
  gem "rspec-rails", "~> 5.0", ">= 5.0.2"
12
-
13
-
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-json_api (1.0.3)
4
+ rspec-json_api (1.1.1)
5
5
  activesupport (>= 6.1.4.1)
6
6
  rails (>= 6.1.4.1)
7
7
  rspec-rails (>= 5.0.2)
@@ -71,23 +71,38 @@ GEM
71
71
  builder (3.2.4)
72
72
  concurrent-ruby (1.1.9)
73
73
  crass (1.0.6)
74
+ date (3.3.4)
74
75
  diff-lcs (1.5.0)
75
76
  erubi (1.10.0)
76
- globalid (1.0.0)
77
- activesupport (>= 5.0)
77
+ globalid (1.2.1)
78
+ activesupport (>= 6.1)
78
79
  i18n (1.9.1)
79
80
  concurrent-ruby (~> 1.0)
80
81
  loofah (2.13.0)
81
82
  crass (~> 1.0.2)
82
83
  nokogiri (>= 1.5.9)
83
- mail (2.7.1)
84
+ mail (2.8.1)
84
85
  mini_mime (>= 0.1.1)
86
+ net-imap
87
+ net-pop
88
+ net-smtp
85
89
  marcel (1.0.2)
86
90
  method_source (1.0.0)
87
- mini_mime (1.1.2)
91
+ mini_mime (1.1.5)
92
+ mini_portile2 (2.7.1)
88
93
  minitest (5.15.0)
89
- nio4r (2.5.8)
90
- nokogiri (1.13.1-x86_64-darwin)
94
+ net-imap (0.4.9.1)
95
+ date
96
+ net-protocol
97
+ net-pop (0.1.2)
98
+ net-protocol
99
+ net-protocol (0.2.2)
100
+ timeout
101
+ net-smtp (0.4.0.1)
102
+ net-protocol
103
+ nio4r (2.7.0)
104
+ nokogiri (1.13.1)
105
+ mini_portile2 (~> 2.7.0)
91
106
  racc (~> 1.4)
92
107
  racc (1.6.0)
93
108
  rack (2.2.3)
@@ -137,7 +152,7 @@ GEM
137
152
  rspec-mocks (~> 3.10)
138
153
  rspec-support (~> 3.10)
139
154
  rspec-support (3.10.3)
140
- sprockets (4.0.2)
155
+ sprockets (4.1.1)
141
156
  concurrent-ruby (~> 1.0)
142
157
  rack (> 1, < 3)
143
158
  sprockets-rails (3.4.2)
@@ -145,14 +160,16 @@ GEM
145
160
  activesupport (>= 5.2)
146
161
  sprockets (>= 3.0.0)
147
162
  thor (1.2.1)
163
+ timeout (0.4.1)
148
164
  tzinfo (2.0.4)
149
165
  concurrent-ruby (~> 1.0)
150
- websocket-driver (0.7.5)
166
+ websocket-driver (0.7.6)
151
167
  websocket-extensions (>= 0.1.0)
152
168
  websocket-extensions (0.1.5)
153
169
  zeitwerk (2.5.4)
154
170
 
155
171
  PLATFORMS
172
+ arm64-darwin-22
156
173
  x86_64-darwin-20
157
174
 
158
175
  DEPENDENCIES
data/README.md CHANGED
@@ -24,7 +24,7 @@ Generate directory tree:
24
24
 
25
25
  rails generate rspec:json_api:install
26
26
 
27
- Require gem assets in your `spec_helper.rb`
27
+ Require gem assets in your `rails_helper.rb`
28
28
  ```ruby
29
29
  Dir[File.join(__dir__, 'rspec', 'json_api', 'types', '*.rb')].each { |file| require file }
30
30
  Dir[File.join(__dir__, 'rspec', 'json_api', 'interfaces', '*.rb')].each { |file| require file }
@@ -66,6 +66,14 @@ RSpec.describe UsersController, type: :controller do
66
66
  expect(response.body).to match_json_schema(expected_schema)
67
67
  end
68
68
  end
69
+
70
+ describe '#update' do
71
+ it 'matches API response' do
72
+ put :update, params: { name: 'John', age: 35 }
73
+
74
+ expect(response.body).to have_no_content
75
+ end
76
+ end
69
77
  end
70
78
  ```
71
79
 
@@ -75,6 +83,11 @@ end
75
83
  expect(response.body).to match_json_schema(expected_schema)
76
84
  ```
77
85
 
86
+ - ### have_no_content
87
+ ```
88
+ expect(response.body).to have_no_content
89
+ ```
90
+
78
91
  ## Interfaces
79
92
  The gem introduces interfaces to reuse them during test matches.
80
93
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Extention methods for hash class
3
+ # Extension methods for hash class
4
4
  class Hash
5
5
  def deep_keys
6
6
  each_with_object([]) do |(k, v), keys|
@@ -10,9 +10,15 @@ module RSpec
10
10
  def compare(actual, expected)
11
11
  return false if actual.blank? && expected.present?
12
12
 
13
- key_paths = actual.deep_key_paths
13
+ keys = expected.deep_key_paths | actual.deep_key_paths
14
14
 
15
- key_paths.all? do |key_path|
15
+ compare_key_paths_and_values(keys, actual, expected)
16
+ end
17
+
18
+ private
19
+
20
+ def compare_key_paths_and_values(keys, actual, expected)
21
+ keys.all? do |key_path|
16
22
  actual_value = actual.dig(*key_path)
17
23
  expected_value = expected.dig(*key_path)
18
24
 
@@ -20,8 +26,6 @@ module RSpec
20
26
  end
21
27
  end
22
28
 
23
- private
24
-
25
29
  def compare_hash_values(actual_value, expected_value)
26
30
  case expected_value
27
31
  when Class
@@ -42,7 +46,7 @@ module RSpec
42
46
  end
43
47
 
44
48
  def compare_regexp(actual_value, expected_value)
45
- actual_value =~ expected_value
49
+ actual_value.to_s =~ expected_value
46
50
  end
47
51
 
48
52
  def compare_proc(actual_value, expected_value)
@@ -88,10 +92,10 @@ module RSpec
88
92
 
89
93
  actual_value.all? { |elem| compare(elem, interface) }
90
94
  else
91
- return false if actual_value.size != expected_value.size
95
+ return false if actual_value&.size != expected_value&.size
92
96
 
93
- actual_value.each_with_index.all? do |elem, index|
94
- elem.is_a?(Hash) ? compare(elem, expected_value[index]) : compare_value(elem, expected_value[index])
97
+ expected_value.each_with_index.all? do |elem, index|
98
+ elem.is_a?(Hash) ? compare(actual_value[index], elem) : compare_value(actual_value[index], elem)
95
99
  end
96
100
  end
97
101
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module JsonApi
5
+ module Matchers
6
+ class HaveNoContent
7
+ def matches?(actual)
8
+ actual == ""
9
+ end
10
+
11
+ def failure_message
12
+ self
13
+ end
14
+
15
+ def failure_message_when_negated
16
+ self
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,6 +11,7 @@ module RSpec
11
11
  end
12
12
 
13
13
  def matches?(actual)
14
+ # Parse JSON to ruby object
14
15
  actual = JSON.parse(actual, symbolize_names: true)
15
16
 
16
17
  # Compare types
@@ -5,5 +5,9 @@ module RSpec
5
5
  def match_json_schema(expected)
6
6
  RSpec::JsonApi::Matchers::MatchJsonSchema.new(expected)
7
7
  end
8
+
9
+ def have_no_content
10
+ RSpec::JsonApi::Matchers::HaveNoContent.new
11
+ end
8
12
  end
9
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module JsonApi
5
- VERSION = "1.0.3"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
@@ -15,6 +15,7 @@ require "extentions/hash"
15
15
  # Load matchers
16
16
  require "rspec/json_api/matchers"
17
17
  require "rspec/json_api/matchers/match_json_schema"
18
+ require "rspec/json_api/matchers/have_no_content"
18
19
 
19
20
  # Load defined types
20
21
  require "rspec/json_api/types/email"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-json_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Gajowiak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-03 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -63,6 +63,7 @@ files:
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
65
  - ".rubocop.yml"
66
+ - ".ruby-version"
66
67
  - CHANGELOG.md
67
68
  - CODE_OF_CONDUCT.md
68
69
  - Gemfile
@@ -84,6 +85,7 @@ files:
84
85
  - lib/rspec/json_api/compare_hash.rb
85
86
  - lib/rspec/json_api/interfaces/example_interface.rb
86
87
  - lib/rspec/json_api/matchers.rb
88
+ - lib/rspec/json_api/matchers/have_no_content.rb
87
89
  - lib/rspec/json_api/matchers/match_json_schema.rb
88
90
  - lib/rspec/json_api/types/email.rb
89
91
  - lib/rspec/json_api/types/uri.rb
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  - !ruby/object:Gem::Version
113
115
  version: '0'
114
116
  requirements: []
115
- rubygems_version: 3.2.16
117
+ rubygems_version: 3.4.10
116
118
  signing_key:
117
119
  specification_version: 4
118
120
  summary: RSpec extension to test JSON API response.