lighthouse-matchers 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa3cc9c2c57e0dae4e2ebb61d281a094354514473b4ff20ed8e6abf67e9991e9
4
- data.tar.gz: 42c1681ad2022e0dc875f715128e14acf3e1fbeffd4755165979796a69da1840
3
+ metadata.gz: 39bae0e8641dae16dd253b900d90ccf0e96008353bebff86bacfc7007d4131ca
4
+ data.tar.gz: 5ec2143cae768123fe66d882800513e1cf4d2e6194d74bb9297fde83bab999f7
5
5
  SHA512:
6
- metadata.gz: be9ce6e8dae7d79907120bc5b0a9f52aec74efb33c10cade08320996f82817ec9e51b118b4335e5d8cb3a1e307df83dfbc236980cb7d59a4bf8fd718310d8ad9
7
- data.tar.gz: af2742c37727f20e3813e72d178c3d19acb0e660063476060b3b290243c71c38d6b7ccf9b579bc3344bc8a0e6b3ed4b4d7dd5eddcd9dd5a6fd009424138fe22b
6
+ metadata.gz: e537f89cf5cb908ec7f4afe6ddfce0cdca25ac710ac7e8ee7365a53630e8b854ba9155f33c1e9c37ed59eae19d62e6194198715ad466f7268b5dd3e45ec66d36
7
+ data.tar.gz: d9ce149527bf757d862d93baf1a1fdc3a5b60064c73d50d5304f5c5ffa36edde525b00a38ce6dc3c96c7516240e8e6b7a7c55a1ec4381a05275dde330da7b346
data/CHANGELOG.md CHANGED
@@ -12,4 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
 
13
13
  ## [1.0.1] - 2019-05-24
14
14
  ### Changed
15
- - Apply bug fixes based on integration with a Ruby on Rails project
15
+ - Apply bug fixes based on integration with a Ruby on Rails project
16
+
17
+ ## [1.0.2] - 2019-08-16
18
+ ### Changed
19
+ - Refactored auditing into a service object (@CaraHill)
20
+ -
21
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighthouse-matchers (1.0.1)
4
+ lighthouse-matchers (1.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -48,4 +48,4 @@ DEPENDENCIES
48
48
  rubocop
49
49
 
50
50
  BUNDLED WITH
51
- 2.0.1
51
+ 2.0.2
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ # Compares a url's actual score to the expected score.
6
+ class AuditService
7
+ def initialize(url, audit, score)
8
+ @url = url
9
+ @audit = audit
10
+ @score = score
11
+ @port = Lighthouse::Matchers.remote_debugging_port
12
+ @runner = Lighthouse::Matchers.runner
13
+ @cmd = Lighthouse::Matchers.lighthouse_cli
14
+ end
15
+
16
+ def passing_score?
17
+ measured_score >= @score
18
+ end
19
+
20
+ private
21
+
22
+ def opts
23
+ "'#{@url}' --quiet --output=json #{"--port=#{@port}" if @port}".strip
24
+ end
25
+
26
+ def output
27
+ @runner.call("#{@cmd} #{opts}")
28
+ end
29
+
30
+ def results
31
+ JSON.parse(output)
32
+ end
33
+
34
+ def measured_score
35
+ results.dig('categories', @audit.to_s, 'score') * 100
36
+ end
37
+ end
@@ -2,28 +2,26 @@
2
2
 
3
3
  require 'rspec/expectations'
4
4
  require 'lighthouse/matchers'
5
+ require 'lighthouse/audit_service'
5
6
  require 'json'
6
7
 
7
8
  RSpec::Matchers.define :pass_lighthouse_audit do |audit, score: nil|
8
- match do |target|
9
- score ||= Lighthouse::Matchers.minimum_score
10
- port = Lighthouse::Matchers.remote_debugging_port
11
- runner = Lighthouse::Matchers.runner
9
+ score ||= Lighthouse::Matchers.minimum_score
12
10
 
13
- url = target.respond_to?(:current_url) ? target.current_url : target
14
- opts = "'#{url}' --quiet --output=json #{"--port=#{port}" if port}".strip
15
- cmd = Lighthouse::Matchers.lighthouse_cli
16
- output = runner.call("#{cmd} #{opts}")
17
- results = JSON.parse(output)
18
- actual_score = results.dig('categories', audit.to_s, 'score') * 100
19
- actual_score >= score
11
+ match do |target|
12
+ AuditService.new(url(target), audit, score).passing_score?
20
13
  end
21
14
 
22
15
  failure_message do |target|
23
- url = target.respond_to?(:current_url) ? target.current_url : target
24
16
  <<~FAIL
25
- expected #{url} to pass Lighthouse #{audit} audit
17
+ expected #{url(target)} to pass Lighthouse #{audit} audit
26
18
  with a minimum score of #{score}
27
19
  FAIL
28
20
  end
21
+
22
+ private
23
+
24
+ def url(target)
25
+ target.respond_to?(:current_url) ? target.current_url : target
26
+ end
29
27
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lighthouse
4
4
  module Matchers
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lighthouse-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh McArthur on behalf of Ackama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2019-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ files:
88
88
  - bin/ci-run
89
89
  - bin/console
90
90
  - bin/setup
91
+ - lib/lighthouse/audit_service.rb
91
92
  - lib/lighthouse/matchers.rb
92
93
  - lib/lighthouse/matchers/rspec.rb
93
94
  - lib/lighthouse/matchers/version.rb