spec/signore/signature_spec.rb in signore-0.1.2 vs spec/signore/signature_spec.rb in signore-0.2.0
- old
+ new
@@ -1,74 +1,94 @@
-# encoding: UTF-8
-
require_relative '../spec_helper'
module Signore describe Signature do
-
- before do
- @confusion, @mad, @compiler, @bruce, @dads, @starwars = YAML.load_file('spec/fixtures/signatures.yml')['signatures']
+ describe '.[]' 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[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
end
describe '#tagged_with?' do
-
it 'says whether a tagged signature is tagged with a given tag' do
- refute @compiler.tagged_with? 'fnord'
- assert @compiler.tagged_with? 'programming'
- assert @compiler.tagged_with? 'tech'
+ sig = Signature[tags: %w[programming tech]]
+ 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 @dads.tagged_with? 'fnord'
+ refute Signature.new.tagged_with? 'fnord'
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.to_s.must_equal text
+ end
- it 'returns a signature formatted with meta information (if available)' do
- @compiler.to_s.must_equal <<-end.dedent.strip
- // sometimes I believe compiler ignores all my comments
- end
-
- @dads.to_s.must_equal <<-end.dedent.strip
+ it 'shows author on its own' do
+ sig = Signature.new 'stay-at-home executives vs. wallstreet dads', 'kodz'
+ sig.to_s.must_equal <<-end.dedent.strip
stay-at-home executives vs. wallstreet dads
[kodz]
end
+ end
- @mad.to_s.must_equal <<-end.dedent.strip
+ 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, 'Gary Barnes', 'asr'
+ 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
- @bruce.to_s.must_equal <<-end.dedent.strip
+ it 'shows source on its own' do
+ text = 'Bruce Schneier knows Alice and Bob’s shared secret.'
+ sig = Signature[text: text, source: 'Bruce Schneier Facts']
+ sig.to_s.must_equal <<-end.dedent.strip
Bruce Schneier knows Alice and Bob’s shared secret.
[Bruce Schneier Facts]
end
+ end
- @confusion.to_s.must_equal <<-end.dedent.strip
+ 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[text: text, author: 'Clive James',
+ subject: 'on Marilyn Monroe']
+ 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
- @starwars.to_s.must_equal <<-end.dedent.strip
+ 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[text: text, subject: 'Star Wars ending explained']
+ 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
end
it 'handles edge cases properly' do
- class SignatureWithMeta < Signature
- attr_accessor :meta
+ YAML.load_file('spec/fixtures/wrapper.yml').each do |sig, wrapped|
+ sig.to_s.must_equal wrapped
end
-
- YAML.load_file('spec/fixtures/wrapper.yml').each do |sample|
- sig = SignatureWithMeta.new sample[:text]
- sig.meta = sample[:meta]
- sig.to_s.must_equal sample[:wrapped]
- end
end
-
end
-
end end