test/triad_test.rb in triad-0.3.0 vs test/triad_test.rb in triad-1.0.0
- old
+ new
@@ -1,6 +1,6 @@
-require 'test_helper'
+require_relative 'test_helper'
describe Triad, '#<<' do
let(:triad){ Triad.new }
it 'shovels 3 item arrays' do
@@ -20,20 +20,35 @@
}
end
it 'rejects arrays with an existing key' do
triad << [:test, 'Test', Object.new]
- assert_raises(Triad::InvalidAddition){
+ error = assert_raises(Triad::InvalidAddition){
triad << [:test, 'More', Object.new]
}
+ assert_match(/key already exists/, error.message)
end
it 'accepts strings as values' do
object = "a string as an value"
triad << [:key, 'Descriptor', object]
assert_equal [object], triad.values(:key)
end
+
+ it "rejects keys that are not Symbols" do
+ error = assert_raises(Triad::InvalidAddition){
+ triad << ["key", "Descriptor", Object.new]
+ }
+ assert_match(/must be a Symbol/, error.message)
+ end
+
+ it "rejects descriptors that are not Strings" do
+ error = assert_raises(Triad::InvalidAddition){
+ triad << [:key, :Descriptor, Object.new]
+ }
+ assert_match(/must be a String/, error.message)
+ end
end
describe Triad, '#update' do
let(:triad){ Triad.new }
@@ -42,10 +57,24 @@
triad << [:test, 'Test', object]
assert_equal ['Test'], triad.descriptors(:test)
triad.update(:test, 'Updated', Object.new)
assert_equal ['Updated'], triad.descriptors(:test)
end
+
+ it "allows a nil object" do
+ triad << [:test, 'Test', nil]
+ assert_equal ['Test'], triad.descriptors(:test)
+ triad.update(:test, 'Updated', nil)
+ assert_equal ['Updated'], triad.descriptors(:test)
+ end
+
+ it "does not allow a nil descriptor" do
+ err = assert_raises(Triad::InvalidAddition){
+ triad.update(:test, nil, Object.new)
+ }
+ assert_equal "the provided descriptor cannot be nil", err.message
+ end
end
describe Triad, '#keys' do
let(:user){ Object.new }
let(:triad){
@@ -130,10 +159,15 @@
it 'errors when the given value is not found' do
assert_raises(Triad::ItemNotPresent){
triad.descriptors(Object.new)
}
end
+
+ it 'assumes nil is a value' do
+ triad.update(:admin, 'Admin', nil)
+ assert_equal ['Admin'], triad.descriptors(:admin)
+ end
end
describe Triad, '#values' do
let(:user){ Object.new }
let(:triad){
@@ -181,6 +215,6 @@
triad.each do |key, descriptor, value|
result << "key: #{key}, descriptor: #{descriptor}, value: #{value.class.name}"
end
assert_equal 'key: admin, descriptor: Admin, value: Object', result
end
-end
\ No newline at end of file
+end