jsi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,7 +38,7 @@ describe JSI::StructJSONCoder do
38
38
  assert_nil(struct_json_coder.dump(nil))
39
39
  end
40
40
  it 'dumps a struct' do
41
- assert_equal({"foo" => "x","bar" => "y"}, struct_json_coder.dump(struct.new('x', 'y')))
41
+ assert_equal({"foo" => "x", "bar" => "y"}, struct_json_coder.dump(struct.new('x', 'y')))
42
42
  end
43
43
  it 'dumps something else' do
44
44
  assert_raises(TypeError) do
@@ -55,7 +55,7 @@ describe JSI::StructJSONCoder do
55
55
  let(:options) { {array: true} }
56
56
  it 'dumps an array of structs' do
57
57
  structs = [struct.new('x', 'y'), struct.new('z', 'q')]
58
- assert_equal([{"foo" => "x","bar" => "y"},{"foo" => "z","bar" => "q"}], struct_json_coder.dump(structs))
58
+ assert_equal([{"foo" => "x", "bar" => "y"}, {"foo" => "z", "bar" => "q"}], struct_json_coder.dump(structs))
59
59
  end
60
60
  end
61
61
  end
@@ -7,7 +7,7 @@ require 'simplecov'
7
7
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
8
  require 'jsi'
9
9
 
10
- # NO EXPECTATIONS
10
+ # NO EXPECTATIONS
11
11
  ENV["MT_NO_EXPECTATIONS"] = ''
12
12
 
13
13
  require 'minitest/autorun'
@@ -19,6 +19,12 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
19
19
  require 'byebug'
20
20
 
21
21
  class JSISpec < Minitest::Spec
22
+ if ENV['JSI_TEST_ALPHA']
23
+ # :nocov:
24
+ define_singleton_method(:test_order) { :alpha }
25
+ # :nocov:
26
+ end
27
+
22
28
  def assert_equal exp, act, msg = nil
23
29
  msg = message(msg, E) { diff exp, act }
24
30
  assert exp == act, msg
@@ -26,4 +32,32 @@ class JSISpec < Minitest::Spec
26
32
  end
27
33
 
28
34
  # register this to be the base class for specs instead of Minitest::Spec
29
- Minitest::Spec.register_spec_type(//, JSISpec)
35
+ Minitest::Spec.register_spec_type(//, JSISpec)
36
+
37
+ # tests support of things that duck-type #to_hash
38
+ class SortOfHash
39
+ def initialize(hash)
40
+ @hash = hash
41
+ end
42
+ def to_hash
43
+ @hash
44
+ end
45
+ include JSI::FingerprintHash
46
+ def fingerprint
47
+ {class: self.class, hash: @hash}
48
+ end
49
+ end
50
+
51
+ # tests support of things that duck-type #to_ary
52
+ class SortOfArray
53
+ def initialize(ary)
54
+ @ary = ary
55
+ end
56
+ def to_ary
57
+ @ary
58
+ end
59
+ include JSI::FingerprintHash
60
+ def fingerprint
61
+ {class: self.class, ary: @ary}
62
+ end
63
+ end
@@ -10,7 +10,7 @@ describe JSI::Util do
10
10
  expected = JSI::JSON::HashNode.new({'a' => 'b', 'c' => 'd', nil => 3}, [])
11
11
  assert_equal(expected, actual)
12
12
  end
13
- it 'stringifies SchemaObjectBase hash keys' do
13
+ it 'stringifies JSI hash keys' do
14
14
  klass = JSI.class_for_schema(type: 'object')
15
15
  expected = JSI.stringify_symbol_keys(klass.new(JSI::JSON::HashNode.new({a: 'b', 'c' => 'd', nil => 3}, [])))
16
16
  actual = klass.new(JSI::JSON::HashNode.new({'a' => 'b', 'c' => 'd', nil => 3}, []))
@@ -52,10 +52,10 @@ describe JSI::Util do
52
52
  expected = JSI::JSON::HashNode.new({'a' => 'b', 'c' => {'d' => 0}, nil => 3}, [])
53
53
  assert_equal(expected, actual)
54
54
  end
55
- it 'deep stringifies SchemaObjectBase instance on initialize' do
55
+ it 'deep stringifies JSI instance' do
56
56
  klass = JSI.class_for_schema(type: 'object')
57
- expected = klass.new(JSI::JSON::HashNode.new({a: 'b', 'c' => {d: 0}, nil => 3}, []))
58
- actual = klass.new(JSI::JSON::HashNode.new({'a' => 'b', 'c' => {'d' => 0}, nil => 3}, []))
57
+ actual = JSI.deep_stringify_symbol_keys(klass.new(JSI::JSON::HashNode.new({a: 'b', 'c' => {d: 0}, nil => 3}, [])))
58
+ expected = klass.new(JSI::JSON::HashNode.new({'a' => 'b', 'c' => {'d' => 0}, nil => 3}, []))
59
59
  assert_equal(expected, actual)
60
60
  end
61
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-20 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -89,6 +89,7 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".simplecov"
92
+ - ".yardopts"
92
93
  - CHANGELOG.md
93
94
  - LICENSE.txt
94
95
  - README.md
@@ -114,6 +115,7 @@ files:
114
115
  - test/jsi_json_node_test.rb
115
116
  - test/jsi_test.rb
116
117
  - test/schema_instance_json_coder_test.rb
118
+ - test/schema_test.rb
117
119
  - test/struct_json_coder_test.rb
118
120
  - test/test_helper.rb
119
121
  - test/util_test.rb
@@ -150,6 +152,7 @@ test_files:
150
152
  - test/jsi_json_node_test.rb
151
153
  - test/jsi_test.rb
152
154
  - test/schema_instance_json_coder_test.rb
155
+ - test/schema_test.rb
153
156
  - test/struct_json_coder_test.rb
154
157
  - test/test_helper.rb
155
158
  - test/util_test.rb