Sha256: 338be0ce1aecb671aaf72d234495482a2f1a4e8c3215d46d2041405fc5c15e18

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

RSpec.shared_examples 'a template' do |filename|

  specify { expect(subject.filename).to eq(filename) }

  describe '#generate' do
    before do
      allow(IO).to receive(:read).
        with(/lib\/hound\/tools\/templates\/_#{filename}$/).and_call_original
      allow($stderr).to receive(:puts)
      allow($stdout).to receive(:puts)
    end

    context "with no #{filename}" do
      before do
        allow(IO).to receive(:read).with(filename).and_raise(Errno::ENOENT)
        allow(IO).to receive(:write).with(filename, anything)
        allow(FileUtils).to receive(:mkpath).with(File.dirname(filename))
      end

      it 'displays the file was created' do
        expect($stdout).to receive(:puts).with("#{filename} created")
        subject.generate
      end

      context "with existing valid #{filename}" do
        let(:contents) { IO.read("lib/hound/tools/templates/_#{filename}") }

        before do
          allow(IO).to receive(:read).with(filename).and_return(contents)
        end

        it 'displays the files was skipped' do
          expect($stdout).to receive(:puts).with("#{filename} (seems ok - skipped)")
          subject.generate
        end

        it 'returns true' do
          expect(subject.generate).to be_truthy
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hound-tools-0.0.6 spec/lib/hound/tools/template_spec.rb
hound-tools-0.0.5 spec/lib/hound/tools/template_spec.rb
hound-tools-0.0.4 spec/lib/hound/tools/template_spec.rb