spec/signore/signature_spec.rb in signore-0.0.0 vs spec/signore/signature_spec.rb in signore-0.1.0

- old
+ new

@@ -3,35 +3,71 @@ require_relative '../spec_helper' module Signore describe Signature do before do - Database.load 'spec/fixtures/signatures.yml' + @confusion, @mad, @compiler, @bruce, @dads, @starwars = YAML.load_file('spec/fixtures/signatures.yml')['signatures'] end - describe '#display' do + describe '#tagged_with?' do - it 'returns a signature formatted with meta information (if available)' do - Database.db[2].display.must_equal '// sometimes I believe compiler ignores all my comments' - Database.db[4].display.must_equal "stay-at-home executives vs. wallstreet dads\n [kodz]" - Database.db[1].display.must_equal "You do have to be mad to work here, but it doesn’t help.\n [Gary Barnes, asr]" - Database.db[3].display.must_equal "Bruce Schneier knows Alice and Bob’s shared secret.\n [Bruce Schneier Facts]" - Database.db[0].display.must_equal "She was good at playing abstract confusion in\nthe same way a midget is good at being short.\n [Clive James on Marilyn Monroe]" - Database.db[5].display.must_equal "Amateur fighter pilot ignores orders, listens to\nthe voices in his head and slaughters thousands.\n [Star Wars ending explained]" + 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' end + it 'says that an untagged signature is not tagged with any tag' do + refute @dads.tagged_with? 'fnord' + end + end - describe '#tagged_with?' do + describe '#to_s' do - it 'says whether a tagged signatura is tagged with a given tag' do - refute Database.db[2].tagged_with? 'fnord' - assert Database.db[2].tagged_with? 'programming' - assert Database.db[2].tagged_with? 'tech' + 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 + stay-at-home executives vs. wallstreet dads + [kodz] + END + + @mad.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 + + @bruce.to_s.must_equal <<-END.dedent.strip + Bruce Schneier knows Alice and Bob’s shared secret. + [Bruce Schneier Facts] + END + + @confusion.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 + + @starwars.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 'says that an untagged signature is not tagged with any tag' do - refute Database.db[4].tagged_with? 'fnord' + it 'handles edge cases properly' do + class SignatureWithMeta < Signature + attr_accessor :meta + 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