Sha256: c3669ec008c542053b856db9c527ec386ed94b982861707a35abc37fbf577e77

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

RSpec.describe Guard::LiveReload::Snippet do
  let(:options) { { foo: :bar } }

  let(:template) { '/foo/livereload.js.erb' }
  let(:contents) { '// <%= options[:foo] %>' }

  subject { described_class.new(template, options) }

  let(:tmpfile) { instance_double(Tempfile) }

  before do
    allow(File).to receive(:expand_path) do |*args|
      fail "stub called for File.expand_path(#{args.map(&:inspect) * ','})"
    end

    allow(IO).to receive(:read) do |*args|
      fail "stub called for IO.read(#{args.map(&:inspect) * ','})"
    end

    allow(IO).to receive(:read).with(template).and_return(contents)

    allow(Tempfile).to receive(:new).and_return(tmpfile)
    allow(tmpfile).to receive(:path).and_return('/tmp/livereload-123')
    allow(tmpfile).to receive(:write)
    allow(tmpfile).to receive(:close)
  end

  describe '#initialize' do
    it 'evaluates the js snippet file' do
      expect(tmpfile).to receive(:write).with('// bar')
      subject
    end

    it 'closes the tmpfile' do
      expect(tmpfile).to receive(:close)
      subject
    end
  end

  describe '#path' do
    it 'is set to a tmpfile with the ERB result' do
      expect(subject.path).to eq '/tmp/livereload-123'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
guard-livereload-2.5.2 spec/lib/guard/livereload/snippet_spec.rb
guard-livereload-2.5.1 spec/lib/guard/livereload/snippet_spec.rb
guard-livereload-2.5.0 spec/lib/guard/livereload/snippet_spec.rb