Sha256: dbb7b0e8364322946cd423e372fdf385946f051a7a580ef9b1455e11eeefa27c

Contents?: true

Size: 1.89 KB

Versions: 67

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe VCR::Cassette::ERBRenderer do
  describe '#render' do
    def render(*args)
      described_class.new(*args).render
    end

    let(:no_vars_content) { '<%= 3 + 4 %>. Some ERB' }
    let(:vars_content) { '<%= var1 %>. ERB with Vars! <%= var2 %>' }

    context 'when ERB is disabled' do
      it 'returns the given template' do
        expect(render(no_vars_content, false)).to eq(no_vars_content)
        expect(render(no_vars_content, nil)).to eq(no_vars_content)
      end
    end

    context 'when ERB is enabled but no variables are passed' do
      it 'renders the file content as ERB' do
        expect(render(no_vars_content, true)).to eq("7. Some ERB")
      end

      it 'raises an appropriate error when the ERB template needs variables' do
        expect {
          render(vars_content, true, "vars")
        }.to raise_error(VCR::Errors::MissingERBVariableError,
          %{The ERB in the vars cassette file references undefined variable var1.  } +
          %{Pass it to the cassette using :erb => #{ {:var1=>"some value"}.inspect }.}
        )
      end

      it 'gracefully handles the template being nil' do
        expect(render(nil, true)).to be_nil
      end
    end

    context 'when ERB is enabled and variables are passed' do
      it 'renders the file content as ERB with the passed variables' do
        expect(render(vars_content, :var1 => 'foo', :var2 => 'bar')).to eq('foo. ERB with Vars! bar')
      end

      it 'raises an appropriate error when one or more of the needed variables are not passed' do
        expect {
          render(vars_content, { :var1 => 'foo' }, "vars")
        }.to raise_error(VCR::Errors::MissingERBVariableError,
          %{The ERB in the vars cassette file references undefined variable var2.  } +
          %{Pass it to the cassette using :erb => #{ {:var1 => "foo", :var2 => "some value"}.inspect }.}
        )
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 9 rubygems

Version Path
cloudsmith-api-1.33.7 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-1.30.0 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.57.1 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.54.15 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.53.79 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.53.17 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.53.3 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.53.1 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.52.121 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.52.92 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.52.79 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.52.5 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.52.0 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.51.93 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.51.38 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.51.37 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.51.34 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.51.22 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/lib/vcr/cassette/erb_renderer_spec.rb