Sha256: 820854b3f9c0871634c415eb2035189a88a51ce58caab50cec0996edee3a22a7
Contents?: true
Size: 2 KB
Versions: 1
Compression:
Stored size: 2 KB
Contents
require 'fileutils' require 'pathname' require 'tempfile' require 'tmpdir' require_relative '../spec_helper' require_relative '../../lib/signore/database' require_relative '../../lib/signore/signature' require_relative '../../lib/signore/tags' module Signore describe Database do describe '#<<' do let(:file) { Tempfile.new('') } let(:sig) { Signature.new(text) } let(:text) { 'Normaliser Unix c’est comme pasteuriser le camembert.' } it 'saves the provided signature to disk' do Database.new(path: Pathname.new(file.path)) << sig file.read.must_include text end it 'returns the saved signature' do Database.new(path: Pathname.new(file.path)).<<(sig).must_equal sig end end describe '#find' do let(:database) { Database.new(path: path, sig_finder: sig_finder) } let(:path) { Pathname.new('spec/fixtures/signatures.yml') } let(:sig_finder) { fake(:sig_finder, as: :class) } let(:sigs) { store.transaction(true) { store['signatures'] } } let(:store) { YAML::Store.new(path) } it 'returns a random signature by default' do stub(sig_finder).find(sigs, tags: Tags.new) { sigs.last } database.find.must_equal sigs.last end it 'returns a random signature based on required and forbidden tags' do tags = Tags.new(forbidden: %w(tech), required: %w(programming security)) stub(sig_finder).find(sigs, tags: tags) { sigs.last } database.find(tags: tags).must_equal sigs.last end it 'doesn’t blow up if the path is missing' do begin tempdir = Dir.mktmpdir path = Pathname.new("#{tempdir}/some_intermediate_dir/sigs.yml") Database.new(path: path).find(tags: Tags.new).must_equal Signature.new ensure FileUtils.rmtree tempdir end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
signore-0.2.3 | spec/signore/database_spec.rb |