virtus-matchers 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,12 @@ module Virtus
|
|
11
11
|
def matches?(klass)
|
12
12
|
@klass = klass
|
13
13
|
attribute = @klass.attribute_set[@name]
|
14
|
-
|
14
|
+
return false unless attribute
|
15
|
+
if @type.class == Array
|
16
|
+
attribute.options[:primitive] == Array && attribute.options[:member_type] == @type.first
|
17
|
+
else
|
18
|
+
attribute.options[:primitive] == @type
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
def failure_message
|
@@ -5,9 +5,10 @@ describe Virtus::Matchers::HaveAttributeMatcher do
|
|
5
5
|
include Virtus
|
6
6
|
|
7
7
|
attribute :foo, String
|
8
|
+
attribute :bar, Array[String]
|
8
9
|
end
|
9
10
|
|
10
|
-
context 'when attribute is defined', 'with
|
11
|
+
context 'when attribute is defined', 'with simple type' do
|
11
12
|
let(:matcher) { described_class.new(:foo, String) }
|
12
13
|
|
13
14
|
it 'should match' do
|
@@ -15,6 +16,22 @@ describe Virtus::Matchers::HaveAttributeMatcher do
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
19
|
+
context 'when attribute is defined', 'with array type', 'and correct member type' do
|
20
|
+
let(:matcher) { described_class.new(:bar, Array[String]) }
|
21
|
+
|
22
|
+
it 'should match' do
|
23
|
+
matcher.matches?(Example).should be_true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when attribute is defined', 'with array type', 'but wrong member type' do
|
28
|
+
let(:matcher) { described_class.new(:bar, Array[Integer]) }
|
29
|
+
|
30
|
+
it 'should not match' do
|
31
|
+
matcher.matches?(Example).should be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
18
35
|
context 'when attribute is defined', 'with wrong type' do
|
19
36
|
let(:matcher) { described_class.new(:foo, Hash) }
|
20
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: virtus
|
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash:
|
138
|
+
hash: 1260615358820155132
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
none: false
|
141
141
|
requirements:
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
segments:
|
146
146
|
- 0
|
147
|
-
hash:
|
147
|
+
hash: 1260615358820155132
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
150
|
rubygems_version: 1.8.24
|