Sha256: c9f7898b982da557232fe6d34668230a6670c545087e734fe585fe4375cc0876

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require_relative '../spec_helper'

module Signore describe Database do
  describe '#find' do
    let(:db)   { Database.new path              }
    let(:path) { 'spec/fixtures/signatures.yml' }

    it 'returns a random signature by default' do
      Database.new(path).find(random: Random.new(1981)).text
        .must_include 'Amateur fighter pilot ignores orders'
      Database.new(path).find(random: Random.new(2009)).text
        .must_include '// sometimes I believe compiler ignores all my comments'
    end

    it 'returns a random signature if the tags are empty' do
      Database.new(path).find(required_tags: [], random: Random.new(2013)).text
        .must_equal '// sometimes I believe compiler ignores all my comments'
    end

    it 'returns a random signature based on provided tags' do
      db.find(required_tags: ['programming']).text
        .must_equal '// sometimes I believe compiler ignores all my comments'
      db.find(required_tags: ['work']).text
        .must_equal 'You do have to be mad to work here, but it doesn’t help.'
    end

    it 'returns a random signature based on required and forbidden tags' do
      forbidden_tags = %w(programming security)
      db.find(required_tags: ['tech'], forbidden_tags: forbidden_tags).text
        .must_equal 'You do have to be mad to work here, but it doesn’t help.'
    end
  end

  describe '#<<' do
    it 'saves the provided signature to disk' do
      text = 'Normaliser Unix c’est comme pasteuriser le camembert.'
      file = Tempfile.new ''
      db   = Database.new file.path
      db  << Signature.new(text)
      file.read.must_include text
    end
  end
end end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
signore-0.2.2 spec/signore/database_spec.rb
signore-0.2.1 spec/signore/database_spec.rb