rspec-resembles_json_matchers 0.7.2 → 0.9.1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +155 -0
  4. data/.travis.yml +5 -6
  5. data/Appraisals +7 -5
  6. data/Changelog.md +16 -0
  7. data/Gemfile +3 -1
  8. data/Guardfile +6 -5
  9. data/LICENSE.txt +13 -0
  10. data/README.md +5 -0
  11. data/Rakefile +2 -0
  12. data/examples/example_spec.rb +67 -63
  13. data/gemfiles/.bundle/config +5 -0
  14. data/gemfiles/rails_5.gemfile +2 -2
  15. data/gemfiles/rails_5.gemfile.lock +100 -67
  16. data/gemfiles/{rails_42.gemfile → rails_6.gemfile} +3 -3
  17. data/gemfiles/rails_6.gemfile.lock +236 -0
  18. data/lib/rspec/resembles_json_matchers.rb +16 -15
  19. data/lib/rspec/resembles_json_matchers/attribute_differ.rb +75 -55
  20. data/lib/rspec/resembles_json_matchers/attribute_matcher.rb +38 -18
  21. data/lib/rspec/resembles_json_matchers/helpers.rb +4 -3
  22. data/lib/rspec/resembles_json_matchers/json_matcher.rb +22 -33
  23. data/lib/rspec/resembles_json_matchers/matcherizer.rb +2 -3
  24. data/lib/rspec/resembles_json_matchers/resembles_any_of_matcher.rb +16 -15
  25. data/lib/rspec/resembles_json_matchers/resembles_array_matcher.rb +2 -4
  26. data/lib/rspec/resembles_json_matchers/resembles_boolean_matcher.rb +4 -1
  27. data/lib/rspec/resembles_json_matchers/resembles_class_matcher.rb +2 -1
  28. data/lib/rspec/resembles_json_matchers/resembles_date_matcher.rb +2 -0
  29. data/lib/rspec/resembles_json_matchers/resembles_hash_matcher.rb +11 -11
  30. data/lib/rspec/resembles_json_matchers/resembles_matcher.rb +8 -16
  31. data/lib/rspec/resembles_json_matchers/resembles_nil_matcher.rb +1 -0
  32. data/lib/rspec/resembles_json_matchers/resembles_numeric_matcher.rb +2 -1
  33. data/lib/rspec/resembles_json_matchers/resembles_route_matcher.rb +6 -3
  34. data/lib/rspec/resembles_json_matchers/resembles_string_matcher.rb +1 -0
  35. data/lib/rspec/resembles_json_matchers/string_indent.rb +4 -2
  36. data/lib/rspec/resembles_json_matchers/version.rb +3 -1
  37. data/rspec-resembles_json_matchers.gemspec +14 -9
  38. metadata +68 -24
  39. data/gemfiles/rails_42.gemfile.lock +0 -183
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 142c673e3380c25a8f69508c2ba4dd7a89bdb11dfe70f2ba0493404396290110
4
- data.tar.gz: 9f36028f25d03b72e791784dbd68a052101ce26ad1a70f5f309624eca0fab425
3
+ metadata.gz: 38281b311384de632c7193ac6934f3d75b7819cd398aa4f2972afb9180e21ef9
4
+ data.tar.gz: 39b792abbcdc3918090865625eeae4afa31943d5a95624a055be3b41e80872dd
5
5
  SHA512:
6
- metadata.gz: 33a000fb317446e635fa617fb7943081add5254aec98c081106925c90b48f0f151c6d27abbbe384b3dd2aed7a6ffdc44008f1fc49b66f8d6af3cf6ce2269f957
7
- data.tar.gz: '0691dffd2f1b9e07a552a5a281a2407da6d0801cd057b01855013b62409ac64df226fabca892f53bf6e70a991ec6a7c52753dae9dc0b7165a99413c0d0696c39'
6
+ metadata.gz: 88c84bf302ab7c9e91708e7a6d2a8547b550f13bbe270782adb9d71543a77f2e08bfc1d9c77b27cd1114ea22ed73bbba474ded3f2c7bf46765fab07d1b3daa56
7
+ data.tar.gz: bbcd7298a08f9382232320b91c95ef999b5ec25eca8617886fb6ae8b1a1a9cd3d49371abd801757c8dccc47f67c62a2e9c6c331e39ba4945d50005cb5dc6cf1c
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .rubocop-*
@@ -0,0 +1,155 @@
1
+ inherit_from:
2
+ - https://relaxed.ruby.style/rubocop.yml
3
+
4
+ require:
5
+ - rubocop-rspec
6
+ - rubocop-performance
7
+
8
+ AllCops:
9
+ DisplayCopNames: true
10
+ DisplayStyleGuide: true
11
+ TargetRubyVersion: 2.6
12
+
13
+ Exclude:
14
+ - "vendor/**/*"
15
+ - "spec/fixtures/**/*"
16
+ - "bin/**/*"
17
+
18
+ Layout:
19
+ Severity: error
20
+ Lint:
21
+ Severity: error
22
+
23
+ Layout/HashAlignment:
24
+ EnforcedHashRocketStyle: table
25
+ EnforcedColonStyle: table
26
+ Layout/LineLength:
27
+ Enabled: true
28
+ Max: 140
29
+ Lint/AmbiguousBlockAssociation:
30
+ Exclude:
31
+ - "spec/**/*" # `expect { }.to change { }` is fine
32
+ Lint/BooleanSymbol:
33
+ Exclude:
34
+ - "spec/**/*" # Symbols like :true get used in these test quite a bit
35
+ Lint/ShadowingOuterLocalVariable:
36
+ # Shadowing outer local variables with block parameters is often useful to
37
+ # not reinvent a new name for the same thing, it highlights the relation
38
+ # between the outer variable and the parameter. The cases where it's actually
39
+ # confusing are rare, and usually bad for other reasons already, for example
40
+ # because the method is too long.
41
+ Enabled: false
42
+ Metrics/BlockLength:
43
+ Exclude:
44
+ - Gemfile
45
+ - Guardfile
46
+ - shared_context
47
+ ExcludedMethods:
48
+ - configure
49
+ - context
50
+ - define
51
+ - describe
52
+ - it
53
+ - namespace
54
+ - specify
55
+ - task
56
+ - shared_examples_for
57
+ - shared_context
58
+ - feature
59
+ Metrics/ClassLength:
60
+ Exclude:
61
+ - "spec/**/*_spec.rb"
62
+ Naming/RescuedExceptionsVariableName:
63
+ PreferredName: ex
64
+ Naming/FileName:
65
+ Enabled: false
66
+ Naming/MethodName:
67
+ Enabled: false # welcome to the visitor pattern
68
+ Naming/MethodParameterName:
69
+ Enabled: false
70
+ Style/ClassAndModuleChildren:
71
+ Enabled: false
72
+ Style/EmptyLiteral:
73
+ Enabled: false
74
+ Style/FormatStringToken:
75
+ Enabled: false
76
+ Style/FrozenStringLiteralComment:
77
+ Enabled: true
78
+ Style/HashEachMethods:
79
+ Enabled: true
80
+ Style/HashSyntax:
81
+ Exclude:
82
+ - Rakefile
83
+ - "**/*.rake"
84
+ Style/HashTransformKeys:
85
+ Enabled: true
86
+ Style/HashTransformValues:
87
+ Enabled: true
88
+ Style/MethodCallWithoutArgsParentheses:
89
+ Enabled: true
90
+ Style/NumericLiterals:
91
+ Enabled: false
92
+ Style/StringLiterals:
93
+ Enabled: true
94
+ EnforcedStyle: double_quotes
95
+ Style/SymbolArray:
96
+ MinSize: 4
97
+
98
+ # 0.81
99
+ Lint/RaiseException:
100
+ Enabled: true
101
+ Lint/StructNewOverride:
102
+ Enabled: false
103
+
104
+ # 0.82
105
+ Layout/SpaceAroundMethodCallOperator:
106
+ Enabled: true
107
+ Style/ExponentialNotation:
108
+ Enabled: true
109
+
110
+ # 0.83
111
+ Layout/EmptyLinesAroundAttributeAccessor:
112
+ Enabled: true
113
+ Style/SlicingWithRange:
114
+ Enabled: true
115
+
116
+ # 0.84
117
+ Lint/DeprecatedOpenSSLConstant:
118
+ Enabled: true
119
+
120
+ # Rspec
121
+ Capybara/FeatureMethods:
122
+ Enabled: false
123
+ RSpec/ContextWording:
124
+ Enabled: false
125
+ RSpec/DescribeClass:
126
+ Enabled: false
127
+ RSpec/DescribedClass:
128
+ Enabled: false
129
+ RSpec/ExampleLength:
130
+ Max: 20
131
+ RSpec/ExampleWording:
132
+ Enabled: false
133
+ RSpec/ExpectChange:
134
+ EnforcedStyle: block
135
+ RSpec/FilePath:
136
+ Enabled: false
137
+ RSpec/ImplicitExpect:
138
+ Enabled: false
139
+ RSpec/LeadingSubject:
140
+ Enabled: false
141
+ RSpec/MessageSpies:
142
+ Enabled: false
143
+ RSpec/MultipleExpectations:
144
+ Max: 4
145
+ RSpec/NestedGroups:
146
+ Max: 4
147
+ RSpec/NotToNot:
148
+ Enabled: false
149
+ RSpec/ExpectInHook:
150
+ Enabled: false
151
+ RSpec/LetSetup:
152
+ Enabled: false
153
+ RSpec/NamedSubject:
154
+ Enabled: false
155
+
@@ -1,13 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.2
4
- - 2.5.0
5
- before_install: gem install bundler
3
+ - "2.5"
4
+ - "2.6"
5
+ - "2.7"
6
+ before_install: gem update --system && gem install bundler
6
7
  gemfile:
7
- - gemfiles/rails_32.gemfile
8
- - gemfiles/rails_42.gemfile
9
- - gemfiles/rails_42_rspec_33.gemfile
10
8
  - gemfiles/rails_5.gemfile
9
+ - gemfiles/rails_6.gemfile
11
10
  matrix:
12
11
  fast_finish: true
13
12
  notifications:
data/Appraisals CHANGED
@@ -1,9 +1,11 @@
1
- appraise "rails-42" do
2
- gem "rails", "~> 4.2"
3
- gem "rspec", "~> 3.4"
4
- end
1
+ # frozen_string_literal: true
5
2
 
6
3
  appraise "rails-5" do
7
- gem "rails", "~> 5.1.0"
4
+ gem "rails", "~> 5.2.0"
8
5
  gem "rspec", "~> 3.6.0"
9
6
  end
7
+
8
+ appraise "rails-6" do
9
+ gem "rails", "~> 6.0.0"
10
+ gem "rspec", "~> 3.9.0"
11
+ end
@@ -1,3 +1,19 @@
1
+ # 0.9.0
2
+
3
+ - ResemblesBoolean doesn't care about the value of the boolean, only that it
4
+ is a boolean.
5
+ - ResemblesAnyOf with non-homogeneous arrays no longer prints errors when the
6
+ overall array matched successfully.
7
+
8
+ # 0.8.0
9
+
10
+ - ResemblesJson now fails if there are unexpected keys in the actual hash
11
+
12
+ # 0.7.3
13
+
14
+ - Add a few more missing render methods
15
+ - Only try to call indifferent_access on Hashes
16
+
1
17
  # 0.7.2
2
18
 
3
19
  - Expose `expected` in the nil matcher so the description can be rendered
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in rspec-json_api_matchers.gemspec
4
6
  gemspec
data/Guardfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
@@ -26,12 +28,12 @@
26
28
 
27
29
  guard :rspec,
28
30
  # cmd: "bin/rspec --no-profile --fail-fast",
29
- cmd: "bin/rspec --no-profile",
30
- failed_mode: :keep,
31
- run_all: { cmd: "bin/rspec --no-profile --tag ~type:feature" }, # skip feature specs on "all"
31
+ cmd: "bin/rspec --no-profile",
32
+ failed_mode: :focus,
33
+ run_all: { cmd: "bin/rspec --no-profile --tag ~type:feature" }, # skip feature specs on "all"
32
34
  notification: true,
33
35
  all_on_start: false,
34
- all_on_pass: false do
36
+ all_on_pass: false do
35
37
  require "guard/rspec/dsl"
36
38
  dsl = Guard::RSpec::Dsl.new(self)
37
39
 
@@ -50,5 +52,4 @@ guard :rspec,
50
52
  watch(%r{^lib/rspec/resembles_json_matchers/(.+_matcher)\.rb$}) do |m|
51
53
  "spec/matchers/#{m[1]}_spec.rb"
52
54
  end
53
-
54
55
  end
@@ -0,0 +1,13 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rspec-json_api_matchers.svg)](https://badge.fury.io/rb/rspec-json_api_matchers)[![Build Status](https://travis-ci.org/paul/rspec-json_api_matchers.svg?branch=master)](https://travis-ci.org/paul/rspec-json_api_matchers)
4
4
 
5
+
5
6
  This gem provides a set of matchers that make testing JSON documents (actually the hashes parsed from them) simpler and more elegant.
6
7
 
7
8
  ## `resemble` Matcher
@@ -193,3 +194,7 @@ Or install it yourself as:
193
194
 
194
195
  Bug reports and pull requests are welcome on GitHub at https://github.com/paul/rspec-json_api_matchers.
195
196
 
197
+ ## License
198
+
199
+
200
+ [![WTFPL](http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl-badge-4.png)][http://www.wtfpl.net/]
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "../spec/spec_helper"
2
4
 
3
5
  RSpec.describe "The resembles json matcher" do
4
6
  include RSpec::ResemblesJsonMatchers
5
7
 
6
- before :all do
8
+ before :suite do
7
9
  puts <<~WARNING
8
10
  NOTE: some of these are expected to fail, they are meant to demonstrate
9
11
  the output generated by failing specs
@@ -13,11 +15,11 @@ RSpec.describe "The resembles json matcher" do
13
15
  describe "a basic json document" do
14
16
  let(:document) do
15
17
  {
16
- "@id": "/posts/2016/test1",
17
- "@type": "Post",
18
- "title": "Hello World!",
19
- "body": "lorem ipsum",
20
- "created_at": "2016-03-01T00:03:42",
18
+ "@id": "/posts/2016/test1",
19
+ "@type": "Post",
20
+ "title": "Hello World!",
21
+ "body": "lorem ipsum",
22
+ "created_at": "2016-03-01T00:03:42",
21
23
  "published_at": "2016-03-10T15:35:00"
22
24
  }
23
25
  end
@@ -25,11 +27,11 @@ RSpec.describe "The resembles json matcher" do
25
27
  specify do
26
28
  expect(document).to resemble_json(
27
29
  {
28
- "@id": "/posts/:year/:title",
29
- "@type": eq("Post"),
30
- "title": "Hello World!",
31
- "body": "lorem ipsum",
32
- "created_at": "2016-03-01T00:03:42",
30
+ "@id": "/posts/:year/:title",
31
+ "@type": eq("Post"),
32
+ "title": "Hello World!",
33
+ "body": "lorem ipsum",
34
+ "created_at": "2016-03-01T00:03:42",
33
35
  "published_at": "2016-03-10T15:35:00"
34
36
  }
35
37
  )
@@ -39,11 +41,11 @@ RSpec.describe "The resembles json matcher" do
39
41
  specify do
40
42
  expect(document).to resemble_json(
41
43
  {
42
- "@id": "/posts/:year/:title",
43
- "@type": eq("PostCollection"),
44
- "title": 42.0,
45
- "body": "lorem ipsum",
46
- "created_at": "2016-03-01T00:03:42",
44
+ "@id": "/posts/:year/:title",
45
+ "@type": eq("PostCollection"),
46
+ "title": 42.0,
47
+ "body": "lorem ipsum",
48
+ "created_at": "2016-03-01T00:03:42",
47
49
  "published_at": "2016-03-10T15:35:00"
48
50
  }
49
51
  )
@@ -54,10 +56,10 @@ RSpec.describe "The resembles json matcher" do
54
56
  specify do
55
57
  expect(document).to resemble_json(
56
58
  {
57
- "@id": "/posts/:year/:title",
58
- "@type": eq("Post"),
59
- "body": "lorem ipsum",
60
- "created_at": "2016-03-01T00:03:42",
59
+ "@id": "/posts/:year/:title",
60
+ "@type": eq("Post"),
61
+ "body": "lorem ipsum",
62
+ "created_at": "2016-03-01T00:03:42",
61
63
  "published_at": "2016-03-10T15:35:00"
62
64
  }
63
65
  )
@@ -68,11 +70,13 @@ RSpec.describe "The resembles json matcher" do
68
70
  specify do
69
71
  expect(document).to resemble_json(
70
72
  {
71
- "@id": "/posts/:year/:title",
72
- "@type": eq("Post"),
73
- "body": "lorem ipsum",
74
- "created_at": "2016-03-01T00:03:42",
75
- "published_at": "2016-03-10T15:35:00"
73
+ "@id": "/posts/:year/:title",
74
+ "@type": eq("Post"),
75
+ "title": "Hello World!",
76
+ "body": "lorem ipsum",
77
+ "created_at": "2016-03-01T00:03:42",
78
+ "published_at": "2016-03-10T15:35:00",
79
+ "updated_at": "2016-03-10T15:40:00"
76
80
  }
77
81
  )
78
82
  end
@@ -82,16 +86,16 @@ RSpec.describe "The resembles json matcher" do
82
86
  describe "complex nested json documents" do
83
87
  let(:document) do
84
88
  {
85
- "@id": "/posts",
86
- "@type": "PostCollection",
89
+ "@id": "/posts",
90
+ "@type": "PostCollection",
87
91
  "nextPage": "/posts?page=2",
88
- "members": [
92
+ "members": [
89
93
  {
90
- "@id": "/posts/2016/test1",
91
- "@type": "Post",
92
- "title": "Hello World!",
93
- "body": "lorem ipsum",
94
- "created_at": "2016-03-01T00:03:42",
94
+ "@id": "/posts/2016/test1",
95
+ "@type": "Post",
96
+ "title": "Hello World!",
97
+ "body": "lorem ipsum",
98
+ "created_at": "2016-03-01T00:03:42",
95
99
  "published_at": "2016-03-10T15:35:00"
96
100
  }
97
101
  ]
@@ -101,16 +105,16 @@ RSpec.describe "The resembles json matcher" do
101
105
  specify do
102
106
  expect(document).to resemble_json(
103
107
  {
104
- "@id": "/posts",
105
- "@type": eq("PostCollection"),
108
+ "@id": "/posts",
109
+ "@type": eq("PostCollection"),
106
110
  "nextPage": "/posts?page=2",
107
- "members": [
111
+ "members": [
108
112
  {
109
- "@id": "/posts/:year/:title",
110
- "@type": eq("Post"),
111
- "title": "Hello World!",
112
- "body": "lorem ipsum",
113
- "created_at": "2016-03-01T00:03:42",
113
+ "@id": "/posts/:year/:title",
114
+ "@type": eq("Post"),
115
+ "title": "Hello World!",
116
+ "body": "lorem ipsum",
117
+ "created_at": "2016-03-01T00:03:42",
114
118
  "published_at": "2016-03-10T15:35:00"
115
119
  }
116
120
  ]
@@ -122,11 +126,11 @@ RSpec.describe "The resembles json matcher" do
122
126
  describe "empty nested documents" do
123
127
  let(:document) do
124
128
  {
125
- "@id": "/posts/2016/test1",
126
- "@type": "Post",
127
- "title": "Hello World!",
128
- "body": "lorem ipsum",
129
- "created_at": "2016-03-01T00:03:42",
129
+ "@id": "/posts/2016/test1",
130
+ "@type": "Post",
131
+ "title": "Hello World!",
132
+ "body": "lorem ipsum",
133
+ "created_at": "2016-03-01T00:03:42",
130
134
  "published_at": "2016-03-10T15:35:00"
131
135
  }
132
136
  end
@@ -134,15 +138,15 @@ RSpec.describe "The resembles json matcher" do
134
138
  specify do
135
139
  expect(document).to resemble_json(
136
140
  {
137
- "@id": "/posts/:year/:title",
138
- "@type": eq("Post"),
139
- "title": "Hello World!",
140
- "body": "lorem ipsum",
141
- "author": {
142
- "@id": "/authors/:id",
141
+ "@id": "/posts/:year/:title",
142
+ "@type": eq("Post"),
143
+ "title": "Hello World!",
144
+ "body": "lorem ipsum",
145
+ "author": {
146
+ "@id": "/authors/:id",
143
147
  "name": eq("Paul")
144
148
  },
145
- "created_at": "2016-03-01T00:03:42",
149
+ "created_at": "2016-03-01T00:03:42",
146
150
  "published_at": "2016-03-10T15:35:00"
147
151
  }
148
152
  )
@@ -152,8 +156,8 @@ RSpec.describe "The resembles json matcher" do
152
156
  describe "empty nested array documents" do
153
157
  let(:document) do
154
158
  {
155
- "@id": "/posts",
156
- "@type": "PostCollection",
159
+ "@id": "/posts",
160
+ "@type": "PostCollection",
157
161
  "nextPage": "/posts?page=2"
158
162
  }
159
163
  end
@@ -161,16 +165,16 @@ RSpec.describe "The resembles json matcher" do
161
165
  specify do
162
166
  expect(document).to resemble_json(
163
167
  {
164
- "@id": "/posts",
165
- "@type": eq("PostCollection"),
168
+ "@id": "/posts",
169
+ "@type": eq("PostCollection"),
166
170
  "nextPage": "/posts?page=2",
167
- "members": [
171
+ "members": [
168
172
  {
169
- "@id": "/posts/:year/:title",
170
- "@type": eq("Post"),
171
- "title": "Hello World!",
172
- "body": "lorem ipsum",
173
- "created_at": "2016-03-01T00:03:42",
173
+ "@id": "/posts/:year/:title",
174
+ "@type": eq("Post"),
175
+ "title": "Hello World!",
176
+ "body": "lorem ipsum",
177
+ "created_at": "2016-03-01T00:03:42",
174
178
  "published_at": "2016-03-10T15:35:00"
175
179
  }
176
180
  ]