spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb in percy-capybara-2.4.0 vs spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb in percy-capybara-2.4.1

- old
+ new

@@ -1,23 +1,23 @@ require 'sprockets' class SimpleRackApp - def self.call(env) + 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, + sprockets_options: sprockets_options ) end let(:environment) do - root = File.expand_path("../../client/testdata", __FILE__) + root = File.expand_path('../../client/testdata', __FILE__) environment = Sprockets::Environment.new(root) environment.append_path '.' environment end let(:digest_enabled) { false } @@ -30,25 +30,25 @@ options end describe '#snapshot_resources' do context 'Rack::Test', type: :feature do - before(:each) { Capybara.app = SimpleRackApp } + before { 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.map(&: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.map(&: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 @@ -67,15 +67,15 @@ '/assets/images/srcset-base.png', '/assets/images/srcset-first.png', '/assets/images/srcset-second.png', '/assets/js/base.js', ] - expect(resources.map { |r| r.resource_url }).to eq(expected_resources) + expect(resources.map(&:resource_url)).to eq(expected_resources) expect(resources.first.content).to include('.colored-by-base') end context 'Rails app' do - before(:each) do + before do # Pretend like we're in a Rails app right now, all we care about is Rails.public_path. rails_double = double('Rails') # Pretend like the entire testdata directory is the public/ folder. expect(rails_double).to receive(:public_path).and_return(environment.root + '/public') expect(loader).to receive(:_rails).at_least(:once).and_return(rails_double) @@ -83,24 +83,25 @@ it 'includes files from the public folder (non-asset-pipeline)' do resources = loader.build_resources # Weak test that more things are in this list, because it merges asset pipeline with public. expect(resources.length).to be > 5 - resource_urls = resources.map { |r| r.resource_url } - expect(resource_urls).to include('/assets/images/bg-relative.png') # From asset pipeline. - expect(resource_urls).to include('/percy-from-public.svg') # Public merged into root. - expect(resource_urls).to_not include('/large-file-skipped.png') # Public merged into root. + resource_urls = resources.map(&:resource_url) + expect(resource_urls).to include('/assets/images/bg-relative.png') # From asset pipeline. + expect(resource_urls).to include('/percy-from-public.svg') # Public merged into root. + expect(resource_urls).not_to include('/large-file-skipped.png') # Public merged into root. end context 'digest enabled' do let(:digest_enabled) { true } it 'only includes pre-compiled, digested files once' do # This makes sure that we correctly merge already-compiled files in the assets directory # with ones from the asset pipeline. This means that Rails users who have # `config.assets.digest = true` set can safely run "rake assets:precompile" before tests. resources = loader.build_resources expected_digest_url = \ - '/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css' + '/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37' \ + 'd898f4db242e20656a1579e.css' digested_resources = resources.select { |r| r.resource_url == expected_digest_url } expect(digested_resources.length).to eq(1) end end end