Sha256: 86295b53dc7230ac1bd0f88a013573552a778228ddf4ab52c1b34e699ba449df

Contents?: true

Size: 1.35 KB

Versions: 34

Compression:

Stored size: 1.35 KB

Contents

require 'lib/spec_helper'
require 'lib/shared/path_reader_shared'
require 'opal/sprockets/path_reader'

describe Opal::Sprockets::PathReader do
  let(:env) { Sprockets::Environment.new }
  let(:context) { double('context', depend_on: nil, depend_on_asset: nil) }
  let(:contents) { File.read(full_path) }
  let(:full_path) { fixtures_dir.join(logical_path+'.js.rb') }
  let(:logical_path) { 'sprockets_file' }
  let(:fixtures_dir) { Pathname('../../fixtures/').expand_path(__FILE__) }

  subject(:path_reader) { described_class.new(env, context) }

  before do
    Opal.paths.each {|p| env.append_path(p)}
    env.append_path fixtures_dir
  end

  include_examples :path_reader do
    let(:path) { logical_path }
  end

  it 'can read stuff from sprockets env' do
    expect(path_reader.read(logical_path)).to eq(contents)
  end

  it 'reads js files processing their directives' do
    path              = 'file_with_directives.js'
    full_path         = fixtures_dir.join(path)
    required_contents = File.read(fixtures_dir.join('required_file.js')).strip
    read_contents     = path_reader.read(path)
    actual_contents   = full_path.read

    expect(actual_contents).to include('//= require')
    expect(read_contents).not_to include('//= require')

    expect(read_contents).to include(required_contents)
    expect(actual_contents).not_to include(required_contents)
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
opal-0.10.6 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.6.beta spec/lib/sprockets/path_reader_spec.rb
opal-0.10.5 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.4 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.3 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.2 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.1 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.rc2 spec/lib/sprockets/path_reader_spec.rb
opal-0.9.4 spec/lib/sprockets/path_reader_spec.rb
opal-0.9.3 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.rc1 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.beta5 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.beta4 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.beta3 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.beta2 spec/lib/sprockets/path_reader_spec.rb
opal-0.10.0.beta1 spec/lib/sprockets/path_reader_spec.rb
opal-0.9.2 spec/lib/sprockets/path_reader_spec.rb
opal-0.9.0 spec/lib/sprockets/path_reader_spec.rb
opal-0.9.0.rc1 spec/lib/sprockets/path_reader_spec.rb