spec/signore/signature_spec.rb in signore-0.2.4 vs spec/signore/signature_spec.rb in signore-0.3.0
- old
+ new
@@ -7,89 +7,107 @@
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, ' \
'‘Punched Card Methods in Scientific Computation’.'
- sig = Signature.new(text, author: 'Paul E. Ceruzzi', source: source,
- subject: 'on Wallace Eckert',
- tags: ['punched cards'])
+ sig = Signature.new(author: 'Paul E. Ceruzzi', source: source,
+ subject: 'on Wallace Eckert',
+ tags: ['punched cards'], text: text)
sig.author.must_equal 'Paul E. Ceruzzi'
sig.source.must_equal source
sig.subject.must_equal 'on Wallace Eckert'
sig.tags.must_equal ['punched cards']
sig.text.must_equal text
end
it 'nils empty parameters' do
- new = Signature.new('', author: '', source: '', subject: '', tags: [])
- new.must_equal Signature.new(nil, author: nil, source: nil,
- subject: nil, tags: nil)
+ new = Signature.new(author: '', source: '', subject: '', tags: [],
+ text: '')
+ new.must_equal Signature.new(author: nil, source: nil, subject: nil,
+ tags: nil, text: nil)
end
end
describe '#tagged_with?' do
it 'says whether a tagged signature is tagged with a given tag' do
- sig = Signature.new('', tags: %w(programming tech))
+ sig = Signature.new(tags: %w(programming tech), text: '')
refute sig.tagged_with?('fnord')
assert sig.tagged_with?('programming')
assert sig.tagged_with?('tech')
end
it 'says that an untagged signature is not tagged with any tag' do
refute Signature.new.tagged_with?('fnord')
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’',
+ tags: %w(/. MySQL), text: text)
+ sig.to_h.must_equal 'author' => 'Anonymous Coward', 'source' => '/.',
+ 'subject' => 'on ‘Monty Wants to Save MySQL’',
+ 'tags' => %w(/. MySQL), 'text' => text
+
+ end
+
+ it 'removes non-existing keys' do
+ assert Signature.new.to_h.empty?
+ end
+ end
+
describe '#to_s' do
it 'does not show meta if there’s nothing to show' do
text = '// sometimes I believe compiler ignores all my comments'
- sig = Signature.new(text)
+ sig = Signature.new(text: text)
sig.to_s.must_equal text
end
it 'shows author on its own' do
- sig = Signature.new('stay-at-home executives vs. wallstreet dads',
- author: 'kodz')
+ sig = Signature.new(author: 'kodz',
+ text: 'stay-at-home executives vs. wallstreet dads')
sig.to_s.must_equal <<-end.dedent.strip
stay-at-home executives vs. wallstreet dads
[kodz]
end
end
it 'shows author and source, comma-separated' do
text = 'You do have to be mad to work here, but it doesn’t help.'
- sig = Signature.new(text, author: 'Gary Barnes', source: 'asr')
+ sig = Signature.new(author: 'Gary Barnes', source: 'asr', text: text)
sig.to_s.must_equal <<-end.dedent.strip
You do have to be mad to work here, but it doesn’t help.
[Gary Barnes, asr]
end
end
it 'shows source on its own' do
text = 'Bruce Schneier knows Alice and Bob’s shared secret.'
- sig = Signature.new(text, source: 'Bruce Schneier Facts')
+ sig = Signature.new(source: 'Bruce Schneier Facts', text: text)
sig.to_s.must_equal <<-end.dedent.strip
Bruce Schneier knows Alice and Bob’s shared secret.
[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(text, author: 'Clive James',
- subject: 'on Marilyn Monroe')
+ sig = Signature.new(author: 'Clive James', subject: 'on Marilyn Monroe',
+ 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]
end
end
it 'shows subject on its own' do
text = 'Amateur fighter pilot ignores orders, listens ' \
'to the voices in his head and slaughters thousands.'
- sig = Signature.new(text, subject: 'Star Wars ending explained')
+ sig = Signature.new(subject: 'Star Wars ending explained', text: text)
sig.to_s.must_equal <<-end.dedent.strip
Amateur fighter pilot ignores orders, listens to
the voices in his head and slaughters thousands.
[Star Wars ending explained]
end