json_matcher 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # JSON Matcher
2
+
3
+ Let you get Difference in two json
4
+
5
+ It checks if the two jsons are similar or not. By similar we can say it sorts the internal arrays and hash to do the same.
6
+ It gives the difference in diff format with colors
7
+
8
+ # Usage
9
+
10
+ JsonMatcher.similar a, b
11
+
12
+ It returns nil if similar and a diff if different
@@ -1,3 +1,3 @@
1
1
  module JsonMatcher
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/json_matcher.rb CHANGED
@@ -22,7 +22,7 @@ module JsonMatcher
22
22
  end
23
23
 
24
24
  def to_s
25
- red { bold {"expected #{@expected.to_json},\ngot #{@actual.to_json}\nDiff:\n+#{@failure_msg[:extra].to_json}\n-#{@failure_msg[:less].to_json}" } }
25
+ red { bold {"Diff:\n+#{@failure_msg[:extra].to_json}\n-#{@failure_msg[:less].to_json}" } }
26
26
  end
27
27
 
28
28
  private
@@ -11,19 +11,19 @@ describe JsonMatcher do
11
11
  it "should check if both json arguments dont match" do
12
12
  actual = { :key => "value1" }.to_json
13
13
  expected = { :key => "value" }.to_json
14
- JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mexpected #{expected},\ngot #{actual}\nDiff:\n+{\"key\":\"value1\"}\n-{\"key\":\"value\"}\e[0m\e[0m"
14
+ JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mDiff:\n+{\"key\":\"value1\"}\n-{\"key\":\"value\"}\e[0m\e[0m"
15
15
  end
16
16
 
17
17
  it "should check if number of keys are unequal" do
18
18
  actual = { :key => "value", :extra_key => "extra_value" }.to_json
19
19
  expected = { :key => "value" }.to_json
20
- JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mexpected #{expected},\ngot #{actual}\nDiff:\n+{\"extra_key\":\"extra_value\"}\n-{}\e[0m\e[0m"
20
+ JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mDiff:\n+{\"extra_key\":\"extra_value\"}\n-{}\e[0m\e[0m"
21
21
  end
22
22
 
23
23
  it "should check if number of keys are equal but values aren't" do
24
24
  actual = { :key => "value", :extra_key => "value" }.to_json
25
25
  expected = { :key => "value", :extra_key => "value_new" }.to_json
26
- JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mexpected #{expected},\ngot #{actual}\nDiff:\n+{\"extra_key\":\"value\"}\n-{\"extra_key\":\"value_new\"}\e[0m\e[0m"
26
+ JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mDiff:\n+{\"extra_key\":\"value\"}\n-{\"extra_key\":\"value_new\"}\e[0m\e[0m"
27
27
  end
28
28
 
29
29
  it "should check if number of keys are equal, values are equal but order is different" do
@@ -41,6 +41,6 @@ describe JsonMatcher do
41
41
  it "should not match if array for the a key doesnt match and give required error" do
42
42
  actual = { :key => "value", :array_key => [1,2,3] }.to_json
43
43
  expected = { :array_key => [3,2,1,4], :key => "value" }.to_json
44
- JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mexpected #{expected},\ngot #{actual}\nDiff:\n+{\"array_key\":[1,2,3]}\n-{\"array_key\":[3,2,1,4]}\e[0m\e[0m"
44
+ JsonMatcher.similar(actual, expected).should == "\e[31m\e[1mDiff:\n+{\"array_key\":[1,2,3]}\n-{\"array_key\":[3,2,1,4]}\e[0m\e[0m"
45
45
  end
46
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-19 00:00:00.000000000Z
12
+ date: 2011-11-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2155964220 !ruby/object:Gem::Requirement
16
+ requirement: &2169413760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2155964220
24
+ version_requirements: *2169413760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: term-ansicolor
27
- requirement: &2155963800 !ruby/object:Gem::Requirement
27
+ requirement: &2169413340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2155963800
35
+ version_requirements: *2169413340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2155963380 !ruby/object:Gem::Requirement
38
+ requirement: &2169412920 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2155963380
46
+ version_requirements: *2169412920
47
47
  description: A gem that matches similar json and ignores order
48
48
  email:
49
49
  - garima.slideshare@gmail.com
@@ -54,6 +54,7 @@ files:
54
54
  - .gitignore
55
55
  - .rvmrc
56
56
  - Gemfile
57
+ - README.md
57
58
  - Rakefile
58
59
  - json_matcher.gemspec
59
60
  - lib/json_matcher.rb