eq_json 1.0.2 → 2.0.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.
@@ -0,0 +1,153 @@
1
+ require 'eq_json'
2
+ require 'json'
3
+ require 'spec_helper'
4
+
5
+ describe 'test debug files' do
6
+
7
+ before(:each) do
8
+ @tmpPath = Dir.tmpdir + File::SEPARATOR;
9
+
10
+ @baseFileNames = %w(expected actual currentExpectedObj, currentActualObj)
11
+ deleteDebugFiles()
12
+
13
+ @actualBooks = [
14
+ {
15
+ bookId: "1",
16
+ name: "Harry Potter and the Sorcerer's Stone",
17
+ author: "J.K. Rowling"
18
+ },
19
+ {
20
+ bookId: "2",
21
+ name: "Eragon",
22
+ author: "Christopher Paolini"
23
+ },
24
+ {
25
+ bookId: "4",
26
+ name: "Effective Java",
27
+ author: "Cannot Remember"
28
+ }
29
+ ]
30
+
31
+ @actual = {
32
+ bookSeller: "amazon",
33
+ bookWholeSellers: {
34
+ publisherInfo: {
35
+ name: "ACME Publisher Inc.",
36
+ publishDate: {
37
+ month: 3,
38
+ day: 23,
39
+ year: 2015
40
+ },
41
+ products: {
42
+ books: @actualBooks
43
+ }
44
+ }
45
+ },
46
+ url: "www.amazon.com"
47
+ }
48
+
49
+ book3Item =
50
+ {
51
+ bookId: "3",
52
+ name: "The Fellowship of the Ring",
53
+ author: "J.R.R. Tolkien"
54
+ }
55
+
56
+ @expectedBooks = [
57
+ {
58
+ bookId: "1",
59
+ name: "Harry Potter and the Sorcerer's Stone",
60
+ author: "J.K. Rowling"
61
+ },
62
+ {
63
+ bookId: "2",
64
+ name: "Eragon",
65
+ author: "Christopher Paolini"
66
+ },
67
+ book3Item
68
+ ]
69
+
70
+ @expected = {
71
+ bookSeller: "amazon",
72
+ bookWholeSellers: {
73
+ publisherInfo: {
74
+ name: "ACME Publisher Inc.",
75
+ publishDate: {
76
+ month: 3,
77
+ day: 23,
78
+ year: 2015
79
+ },
80
+ products: {
81
+ books: @expectedBooks
82
+ }
83
+ }
84
+ },
85
+ url: "www.amazon.com"
86
+ }
87
+
88
+ @customMatcher=EqualJson.new(@expected)
89
+
90
+ expect(@customMatcher.matches?(@actual)).to eq(false)
91
+
92
+ expectedJson=@expected.to_json;
93
+ actualJson=@actual.to_json;
94
+
95
+ @expectedErrorMessage= "Expected: #{expectedJson}\n" +
96
+ makeGreen(" Actual: #{actualJson}") + "\n" +
97
+ "\nDiff:\n" +
98
+ "JSON path $.bookWholeSellers.publisherInfo.products.books[] could not find:\n" +
99
+ "#{book3Item.to_json}\n" +
100
+ "in actual\n"
101
+
102
+ end
103
+
104
+ after(:each) do
105
+ RSpec.configure do |c|
106
+ c.json_debug_config=false
107
+ end
108
+ end
109
+
110
+ it 'test debug files generated when json_debug_config true' do
111
+
112
+ RSpec.configuration.json_debug_config=true;
113
+
114
+ expect(@customMatcher.failure_message).to eq(@expectedErrorMessage)
115
+
116
+ assertJson("expected", @expected)
117
+ assertJson("actual", @actual)
118
+ assertJson("currentExpectedObj", @expectedBooks)
119
+ assertJson("currentActualObj", @actualBooks)
120
+
121
+ expect(@expected).not_to eq_json(@actual)
122
+
123
+ end
124
+
125
+ it 'test debug files not generated when json_debug_config false' do
126
+
127
+ RSpec.configuration.json_debug_config=false;
128
+
129
+ expect(@customMatcher.failure_message).to eq(@expectedErrorMessage)
130
+
131
+ @baseFileNames.each() do |baseFileName|
132
+ expect(File.exist?(@tmpPath + baseFileName + ".json")).to be false
133
+ end
134
+
135
+ expect(@expected).not_to eq_json(@actual)
136
+ end
137
+ end
138
+
139
+ def assertJson(fileName, expectedHash)
140
+ expectedFromFile = File.read @tmpPath + fileName + ".json"
141
+ tempFileExpected = JSON.parse(expectedFromFile)
142
+
143
+ expect(tempFileExpected).to eq(JSON.parse(JSON.pretty_generate(expectedHash)))
144
+ end
145
+
146
+ def deleteDebugFiles()
147
+
148
+ @baseFileNames.each do |baseFileName|
149
+ fileName = @tmpPath + baseFileName + ".json"
150
+ File.delete(fileName) if File.exist?(fileName)
151
+ end
152
+
153
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,7 @@ RSpec.configure do |c|
4
4
  c.filter_run focus: true
5
5
  c.run_all_when_everything_filtered = true
6
6
  c.add_setting :json_debug_config
7
- c.json_debug_config=true
7
+ c.json_debug_config=false
8
8
  end
9
9
 
10
10
  def makeGreen(text)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eq_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David M. Rhodes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -68,17 +82,22 @@ files:
68
82
  - Rakefile
69
83
  - TODO.txt
70
84
  - eq_json.gemspec
85
+ - lib/array_with_key_message_gen.rb
71
86
  - lib/colorizer.rb
87
+ - lib/debug_dumper.rb
72
88
  - lib/eq_json.rb
73
89
  - lib/eq_json_array.rb
90
+ - lib/eq_json_array_with_key.rb
74
91
  - lib/message_generator.rb
75
92
  - lib/version/version.rb
76
93
  - spec/features/colorizer_spec.rb
77
94
  - spec/features/eq_json_spec.rb
95
+ - spec/features/test_eq_json_array_with_key_size_mismatch_spec.rb
96
+ - spec/features/test_eq_json_array_with_key_spec.rb
78
97
  - spec/features/test_nested_array_spec.rb
79
98
  - spec/features/test_nested_object_spec.rb
80
99
  - spec/features/test_top_level_array_spec.rb
81
- - spec/features/test_write_json_tmp.rb
100
+ - spec/features/test_write_json_tmp_spec.rb
82
101
  - spec/spec_helper.rb
83
102
  homepage: http://rubygems.org/gems/eq_json
84
103
  licenses:
@@ -103,12 +122,14 @@ rubyforge_project:
103
122
  rubygems_version: 2.0.14.1
104
123
  signing_key:
105
124
  specification_version: 4
106
- summary: RSpec equality matcher that to compare JSON
125
+ summary: RSpec equality matcher that compares JSON
107
126
  test_files:
108
127
  - spec/features/colorizer_spec.rb
109
128
  - spec/features/eq_json_spec.rb
129
+ - spec/features/test_eq_json_array_with_key_size_mismatch_spec.rb
130
+ - spec/features/test_eq_json_array_with_key_spec.rb
110
131
  - spec/features/test_nested_array_spec.rb
111
132
  - spec/features/test_nested_object_spec.rb
112
133
  - spec/features/test_top_level_array_spec.rb
113
- - spec/features/test_write_json_tmp.rb
134
+ - spec/features/test_write_json_tmp_spec.rb
114
135
  - spec/spec_helper.rb
@@ -1,95 +0,0 @@
1
- require 'eq_json'
2
- require 'json'
3
- require 'spec_helper'
4
-
5
- xit 'test actual does not contain an element in expected' do
6
-
7
- actual = {
8
- bookSeller: "amazon",
9
- bookWholeSellers: {
10
- publisherInfo: {
11
- name: "ACME Publisher Inc.",
12
- publishDate: {
13
- month: 3,
14
- day: 23,
15
- year: 2015
16
- },
17
- products: {
18
- books: [
19
- {
20
- bookId: "1",
21
- name: "Harry Potter and the Sorcerer's Stone",
22
- author: "J.K. Rowling"
23
- },
24
- {
25
- bookId: "2",
26
- name: "Eragon",
27
- author: "Christopher Paolini"
28
- },
29
- {
30
- bookId: "4",
31
- name: "Effective Java",
32
- author: "Cannot Remember"
33
- }
34
- ]
35
- }
36
- }
37
- },
38
- url: "www.amazon.com"
39
- }
40
-
41
- book3Item =
42
- {
43
- bookId: "3",
44
- name: "The Fellowship of the Ring",
45
- author: "J.R.R. Tolkien"
46
- }
47
-
48
- expected = {
49
- bookSeller: "amazon",
50
- bookWholeSellers: {
51
- publisherInfo: {
52
- name: "ACME Publisher Inc.",
53
- publishDate: {
54
- month: 3,
55
- day: 23,
56
- year: 2015
57
- },
58
- products: {
59
- books: [
60
- {
61
- bookId: "1",
62
- name: "Harry Potter and the Sorcerer's Stone",
63
- author: "J.K. Rowling"
64
- },
65
- {
66
- bookId: "2",
67
- name: "Eragon",
68
- author: "Christopher Paolini"
69
- },
70
- book3Item
71
- ]
72
- }
73
- }
74
- },
75
- url: "www.amazon.com"
76
- }
77
-
78
- customMatcher=EqualWithOutOrderJson.new(expected)
79
-
80
- expect(customMatcher.matches?(actual)).to eq(false)
81
-
82
- expectedJson=expected.to_json;
83
- actualJson=actual.to_json;
84
-
85
- String expectedErrorMessage= "Expected: #{expectedJson}\n" +
86
- makeGreen(" Actual: #{actualJson}") + "\n" +
87
- "\nDiff:\n" +
88
- "JSON path $.bookWholeSellers.publisherInfo.products.books[] could not find:\n" +
89
- "#{book3Item.to_json}\n" +
90
- "in actual\n"
91
-
92
- expect(customMatcher.failure_message).to eq(expectedErrorMessage)
93
-
94
- expect(expected).not_to eq_json(actual)
95
- end