spec/lib/rspec-virtus/matcher_spec.rb in rspec-virtus-0.0.1 vs spec/lib/rspec-virtus/matcher_spec.rb in rspec-virtus-0.1.0
- old
+ new
@@ -2,16 +2,16 @@
require 'virtus'
describe RSpec::Virtus::Matcher do
let(:instance) { described_class.new(attribute_name) }
let(:attribute_name) { :the_attribute }
- let(:type) { String }
class DummyVirtus
include Virtus
attribute :the_attribute, String
+ attribute :the_array_attribute, Array[String]
end
describe '#matches?' do
subject { instance.matches?(actual) }
let(:actual) { DummyVirtus }
@@ -21,42 +21,89 @@
expect(subject).to eql(true)
end
end
context 'successful match on attribute name and type' do
+ before do
+ instance.of_type(String)
+ end
+
it 'returns true' do
expect(subject).to eql(true)
end
end
+ context 'successful match on attribute name, type and member_type' do
+ let(:attribute_name) { :the_array_attribute }
+
+ before do
+ instance.of_type(Array, member_type: String)
+ end
+
+ it 'returns true' do
+ expect(subject).to eql(true)
+ end
+ end
+
context 'unsuccessful match on attribute name' do
let(:attribute_name) { :something_else }
it 'returns false' do
expect(subject).to eql(false)
end
end
context 'unsuccessful match on attribute name and type' do
let(:attribute_name) { :something_else }
- let(:type) { Integer }
+ before do
+ instance.of_type(Integer)
+ end
+
it 'returns false' do
expect(subject).to eql(false)
end
end
- end
- describe '#of_type' do
- subject { instance.of_type(type) }
+ context 'unsuccessful match on attribute name, type and member_type' do
+ let(:attribute_name) { :the_array_attribute }
- it 'adds an option to allow the type to be checked' do
- options_type = subject.instance_variable_get(:@options)[:type]
- expect(options_type).to eql(type)
+ before do
+ instance.of_type(Array, member_type: Integer)
+ end
+
+ it 'returns false' do
+ expect(subject).to eql(false)
+ end
end
+ end
+ describe '#of_type' do
+ subject { instance.of_type(String) }
+
it 'returns itsself so it can be chained' do
expect(subject).to eql(instance)
+ end
+
+ context "singular values" do
+ it 'adds an option to allow the type to be checked' do
+ options_type = subject.instance_variable_get(:@options)[:type]
+ expect(options_type).to eql(String)
+ end
+ end
+
+ context "arrays of values" do
+ subject { instance.of_type(Array, member_type: String) }
+
+ it 'adds an option to allow the type to be checked' do
+ options_type = subject.instance_variable_get(:@options)[:type]
+ expect(options_type).to eql(Array)
+ end
+
+ it 'adds an option to allow the member_type to be checked' do
+ member_options_type = subject.instance_variable_get(:@options)[:member_type]
+ expect(member_options_type).to eql(String)
+ end
end
end
describe '#failure_message' do
subject { instance.negative_failure_message }