Sha256: 4daa07d946931e7419be15c0ba050dfe6a491ce1bee452f0ce1293830478cae7

Contents?: true

Size: 1.71 KB

Versions: 18

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require 'fakefs/spec_helpers'
require 'spec_helper'

module Quby::Questionnaires::Repos
  describe DiskRepo do
    it_behaves_like 'a questionnaire repository' do
      before { @repo_path = Dir.mktmpdir }
      after  { FileUtils.remove_entry_secure(@repo_path) }

      let(:repo) { DiskRepo.new(@repo_path) }
    end

    context 'when integrated' do
      it_behaves_like 'a valid backend for the questionnaires api'
    end

    context 'in isolation' do
      include FakeFS::SpecHelpers
      before { FileUtils.mkdir_p("/tmp") }
      let(:repo) { DiskRepo.new("/tmp") }

      describe '#find' do
        let(:key) { "test" }
        let(:sourcecode) { "title 'foo'" }

        it 'finds one questionnaire' do
          File.open("/tmp/#{key}.rb", "w") { |f| f.write sourcecode }
          questionnaire = repo.find(key)
          expect(questionnaire.key).to eq(key)
          expect(questionnaire.sourcecode).to eq "title 'foo'"
        end

        it 'raises QuestionnaireNotFound if it doesnt exist' do
          allow(repo).to receive(:exists?).and_return(false)
          expect { repo.find(key) }.to raise_error(QuestionnaireNotFound)
        end
      end

      describe '#exists?' do
        it 'returns true if file exists' do
          FileUtils.touch("/tmp/test.rb")
          expect(repo.exists?("test")).to be_truthy
        end

        it 'returns false if file does not exist' do
          expect(repo.exists?("test")).to be_falsey
        end
      end

      describe '#all' do
        it 'finds all questionnaires' do
          FileUtils.touch("/tmp/a.rb")
          FileUtils.touch("/tmp/b.rb")
          expect(repo.all.map(&:key)).to eq %w(a b)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
quby-5.0.4 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.3 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.2 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.1 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.0 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-4.0.4 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.0.pre4 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.0.pre3 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.0.pre2 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-5.0.0.pre1 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-4.0.3 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-4.0.2 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-4.0.1 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-4.0.0 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-3.2.2 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-3.2.1 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-3.2.0 spec/quby/questionnaires/repos/disk_repo_spec.rb
quby-3.2.0.pre.pre1 spec/quby/questionnaires/repos/disk_repo_spec.rb