Sha256: b34be315c8e93a30c980a1706eefa60b5b4eac0919555fa7fae425eed3576c47

Contents?: true

Size: 1.86 KB

Versions: 9

Compression:

Stored size: 1.86 KB

Contents

require 'sprockets'

class SimpleRackApp
  def self.call(env)
    [200, {}, 'Hello World']
  end
end

RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
  let(:loader) do
    described_class.new(
      page: page,
      sprockets_environment: environment,
      sprockets_options: sprockets_options,
    )
  end
  let(:environment) do
    root = File.expand_path("../../client/testdata", __FILE__)
    environment = Sprockets::Environment.new(root)
    environment.append_path '.'
    environment
  end
  let(:sprockets_options) do
    options = double('options')
    allow(options).to receive(:precompile).and_return([/(?:\/|\\|\A)base\.(css|js)$|\.map/])
    allow(options).to receive(:digest).and_return(false)
    options
  end

  describe '#snapshot_resources' do
    context 'Rack::Test', type: :feature do
      before(:each) { Capybara.app = SimpleRackApp }

      it 'returns the root HTML resource' do
        visit '/'
        resources = loader.snapshot_resources
        expect(resources.map { |r| r.resource_url }).to eq(["/"])
        expect(resources.first.is_root).to eq(true)
        expect(resources.first.content).to include('Hello World')
      end
    end
    context 'Capybara::Webkit', type: :feature, js: true do
      it 'returns the root HTML resource' do
        visit '/'
        resources = loader.snapshot_resources
        expect(resources.map { |r| r.resource_url }).to eq(["/"])
        expect(resources.first.is_root).to eq(true)
        expect(resources.first.content).to include('Hello World!</body></html>')
      end
    end
  end
  describe '#build_resources', type: :feature do
    it 'returns "build resources" from filtered sprockets paths' do
      resources = loader.build_resources
      expect(resources.map { |r| r.resource_url }).to eq(["/assets/css/base.css"])
      expect(resources.first.content).to include('.colored-by-base')
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
percy-capybara-1.1.0 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-1.0.0 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.7.0 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.6.1 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.6.0 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.5.0 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.4.12 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.4.11 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb
percy-capybara-0.4.10 spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb