test/signore/signature_test.rb in signore-0.4.2 vs test/signore/signature_test.rb in signore-0.5.0
- old
+ new
@@ -1,10 +1,13 @@
+# frozen_string_literal: true
+
require 'yaml'
require_relative '../test_helper'
+require_relative '../../lib/signore/mapper'
require_relative '../../lib/signore/signature'
-module Signore
+module Signore # rubocop:disable Metrics/ModuleLength
describe Signature do
describe '.new' do
it 'instantiates Signatures via parameters' do
source = 'A History of Modern Computing'
text = 'In 1940 he summarized his work in an influential book, ' \
@@ -20,15 +23,25 @@
end
it 'nils empty parameters' do
new = Signature.new(author: '', source: '', subject: '', tags: [],
text: '')
- _(new).must_equal Signature.new(author: nil, source: nil, subject: nil,
- tags: nil, text: nil)
+ _(new).must_equal Signature.new(author: '', source: '', subject: '',
+ tags: [], text: '')
end
end
+ describe '#empty?' do
+ it 'is true when the Signature is a null object' do
+ assert Signature.new.empty?
+ end
+
+ it 'is false when the Signature has some text' do
+ refute Signature.new(text: 'Node.jk').empty?
+ end
+ end
+
describe '#to_h' do
it 'returns a String-keyed Hash representation of the Signature' do
text = 'For the sake of topic titles, I’d rather if Monty saved Python.'
sig = Signature.new(author: 'Anonymous Coward', source: '/.',
subject: 'on ‘Monty Wants to Save MySQL’',
@@ -80,18 +93,16 @@
[Bruce Schneier Facts]
end
end
it 'shows author and subject, space separated' do
- text = 'She was good at playing abstract confusion ' \
- 'in the same way a midget is good at being short.'
- sig = Signature.new(author: 'Clive James', subject: 'on Marilyn Monroe',
- text: text)
+ text = 'More gangland camp than neo-noir.'
+ sig = Signature.new(author: 'Nicholas Christopher',
+ subject: 'on Pulp Fiction', text: text)
_(sig.to_s).must_equal <<-end.dedent.strip
- She was good at playing abstract confusion in
- the same way a midget is good at being short.
- [Clive James on Marilyn Monroe]
+ More gangland camp than neo-noir.
+ [Nicholas Christopher on Pulp Fiction]
end
end
it 'shows subject on its own' do
text = 'Amateur fighter pilot ignores orders, listens ' \
@@ -104,10 +115,10 @@
end
end
it 'handles edge cases properly' do
YAML.load_file('test/fixtures/wrapper.yml').each do |sig, wrapped|
- _(sig.to_s).must_equal wrapped
+ _(Mapper.from_h(sig.to_h).to_s).must_equal wrapped
end
end
end
end
end