virtus-matchers 0.1.0 → 0.2.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.
@@ -3,7 +3,7 @@
3
3
  module Virtus
4
4
  module Matchers
5
5
  class HaveAttributeMatcher
6
- def initialize(name, type)
6
+ def initialize(name, type = nil)
7
7
  @name = name
8
8
  @type = type
9
9
  end
@@ -28,7 +28,9 @@ module Virtus
28
28
 
29
29
  def description
30
30
  type = @type.class == Array ? "Array#{@type}" : @type
31
- "have attribute #{@name} of type #{type}#{coercer_description}"
31
+ str = "have attribute #{@name}"
32
+ str += " of type #{type}#{coercer_description}" unless @type.nil?
33
+ str
32
34
  end
33
35
 
34
36
  def failure_message
@@ -37,7 +39,7 @@ module Virtus
37
39
 
38
40
  private
39
41
  def valid_type
40
- @attribute.primitive == @type
42
+ @type.nil? || @attribute.primitive == @type
41
43
  end
42
44
 
43
45
  def valid_coercer
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Virtus
4
4
  module Matchers
5
- VERSION = '0.1.0'.freeze
5
+ VERSION = '0.2.0'.freeze
6
6
  end
7
7
  end
@@ -6,12 +6,26 @@ describe Virtus::Matchers::HaveAttributeMatcher do
6
6
  class Example
7
7
  include Virtus.model
8
8
 
9
+ attribute :any
9
10
  attribute :foo, String
10
11
  attribute :bar, Array[String]
11
12
  attribute :baz, Array
12
13
  attribute :lol, DateTime, coercer: FakeCoercer
13
14
  end
14
15
 
16
+ context 'when attribute is defined', 'with no type' do
17
+ let(:matcher) { described_class.new(:any) }
18
+
19
+ it 'should match' do
20
+ matcher.matches?(Example).should be_true
21
+ end
22
+
23
+ it 'should have a description' do
24
+ matcher.matches?(Example)
25
+ matcher.description.should == 'have attribute any'
26
+ end
27
+ end
28
+
15
29
  context 'when attribute is defined', 'with simple type' do
16
30
  let(:matcher) { described_class.new(:foo, String) }
17
31
 
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.1.0
4
+ version: 0.2.0
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: 2013-10-28 00:00:00.000000000 Z
12
+ date: 2014-02-06 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: -3202611215522321042
138
+ hash: -4359705235092573732
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: -3202611215522321042
147
+ hash: -4359705235092573732
148
148
  requirements: []
149
149
  rubyforge_project:
150
150
  rubygems_version: 1.8.23