rspec_structure_matcher 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97089c3a4fd2b002689a6a2a3e09de64aa3ee1eb
4
- data.tar.gz: 5ad3e4fddee55e825f44b509991fef636743d8c3
3
+ metadata.gz: e2e9d7803cb8b87dca184bd5c1bf8da9afc4e0e8
4
+ data.tar.gz: be43094cf44054666ae60a1c7acf9f1319585994
5
5
  SHA512:
6
- metadata.gz: a68a9bc2ab6232520560706094bad4694babf7ec0e2f9097f1648e74f210333101cd082a281aa04400fbc63e3dd602e8837c1fc2a67d7220bad967db3b64f530
7
- data.tar.gz: 01b45d272f2e2069bfd914aa067ab20bbe76c0a130e807cbb32e6724761f25a254e94145be616ef301e5279331b7da4e276bf5f8a4000b8864a5a0442cddd9e0
6
+ metadata.gz: 8998b89b8c27426a32ab5ab2c084f50b7ab8fdf1a7693d356ce05f31159f77b7144658186e1fd95314051e3be4e6eb1c7911aef7ec9d1c9d84b2a20459a267b4
7
+ data.tar.gz: c1d1c69fc69fad491623e5fbaf850d275e1b268bf5260d1b809cf860538ab9c64ef0b080a71b8a8e8159b0e4767cdf9da50c1e8d84687010b7afccfdfeed8654
@@ -1,4 +1,4 @@
1
- RSpec::Matchers.define :have_structure do |expected|
1
+ RSpec::Matchers.define :have_structure do |expected, opts|
2
2
  match do |actual|
3
3
  invalid_items(actual, expected).empty?
4
4
  end
@@ -10,12 +10,24 @@ RSpec::Matchers.define :have_structure do |expected|
10
10
 
11
11
  def invalid_items(actual, expected)
12
12
  expected.each_with_object({}) do |(key, value), memo|
13
- if !actual.has_key?(key.to_s) || !value_match(actual[key.to_s], value)
13
+ if !has_key?(actual, key) || !value_match(get_key(actual, key), value)
14
14
  memo[key] = value
15
15
  end
16
16
  end
17
17
  end
18
18
 
19
+ def has_key?(actual, key)
20
+ actual.key?(key.to_s) || actual.key?(key.to_sym)
21
+ end
22
+
23
+ def get_key(actual, key)
24
+ if actual.key?(key.to_s)
25
+ actual[key.to_s]
26
+ else
27
+ actual[key.to_sym]
28
+ end
29
+ end
30
+
19
31
  def value_match(actual_value, expected_value)
20
32
  if expected_value.is_a?(Regexp)
21
33
  actual_value =~ expected_value
@@ -1,3 +1,3 @@
1
1
  module RspecStructureMatcher
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -51,4 +51,19 @@ describe 'have_structure' do
51
51
  }.not_to raise_error
52
52
  end
53
53
  end
54
+
55
+ context 'when there are symbol keys' do
56
+ let(:structure) {
57
+ {
58
+ :foo => 'baz',
59
+ 'bar' => 'baz'
60
+ }
61
+ }
62
+
63
+ it 'raise no error' do
64
+ expect {
65
+ expect(structure).to have_structure(expected_structure)
66
+ }.not_to raise_error
67
+ end
68
+ end
54
69
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_structure_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Marklove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-24 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Rspec matchers for structured JSON responses. Compare expected keys,
@@ -60,7 +60,7 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
63
+ - ".gitignore"
64
64
  - Gemfile
65
65
  - LICENSE.txt
66
66
  - README.md
@@ -81,17 +81,17 @@ require_paths:
81
81
  - lib
82
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.1.11
94
+ rubygems_version: 2.2.2
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Rspec matchers for structured JSON responses.