generic_test 0.2.2 → 0.3.0

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: f6379c81a2dea26407fa5633791cb839909581636ae394a3f691e89a25a0d6c6
4
- data.tar.gz: a2baae840463737782dc39a89a91b1cc34a4c865b4e1e542a9e67c647797e337
3
+ metadata.gz: ffa3efa41fd3a9b55a1ab5a258d235dbc66a1b49140e860a0dc14fa7171d1c54
4
+ data.tar.gz: 6661eaf0388ee25e92d75d4db9a9c9cd4c30b2a3415729fb4d5679e0661cfe78
5
5
  SHA512:
6
- metadata.gz: 10440d8210e40574dba8ec815443bed05a640ec3bd303f5a78ee8d035767e1c8faa03711446664083b4a2b6196b5f06b9db1e28b4477614965e3e8774b94afd6
7
- data.tar.gz: ad67a5d1996580967d7deda6970a15a99cb86d96bedbb6168e5c0420c6e117bb13f62751ed14661a4cbd45f9364388bbe4a1e337ffc05da154c80cf1a8e222de
6
+ metadata.gz: 430e5e3e718cffbf314033ae023382f160f7abb6f3ac81bba0de0abac0cc084ce784484c94707aa048c2f9486fd6c248eb51eeda73f011f25a246caa42647bca
7
+ data.tar.gz: bcdaa788d1a6148c836de1785c45340dcb9a15608573590eca035915c9fa7eed4003d46f060c750e241d3d06fa051f98ec42293f8f4834665208f99241e9ecfe
data/.gitlab-ci.yml CHANGED
@@ -8,7 +8,7 @@ docker_build:
8
8
  # Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
9
9
  DOCKER_HOST: tcp://docker:2376
10
10
  DOCKER_TLS_CERTDIR: "/certs"
11
- stage: test # Part of a later stage
11
+ stage: deploy # Part of a later stage
12
12
  services:
13
13
  - docker:20.10.11-dind
14
14
  image: docker:20.10.11
@@ -18,9 +18,9 @@ docker_build:
18
18
  - docker build -t $CI_REGISTRY_IMAGE:latest .
19
19
  - docker run -t $CI_REGISTRY_IMAGE:latest generic_test page samuel-garratt.gitlab.io/generic_test/about.html
20
20
  - docker push $CI_REGISTRY_IMAGE:latest
21
- # only:
22
- # - master
23
- # needs: ["test"]
21
+ only:
22
+ - master
23
+ needs: ["test"]
24
24
  except:
25
25
  changes:
26
26
  - "*.md"
@@ -51,7 +51,7 @@ example_test:
51
51
  artifacts:
52
52
  paths:
53
53
  - logs/*.xml
54
- - reports
54
+ - logs/*.html
55
55
  reports:
56
56
  junit: logs/*.xml
57
57
  expire_in: 1 week
data/.rspec CHANGED
@@ -1,5 +1,5 @@
1
1
  --format documentation
2
- --format html --out report.html
2
+ --format html --out logs/report.html
3
3
  --color
4
4
  --require spec_helper
5
5
  --format RspecJunitFormatter --out logs/page_<%= ENV['PAGE_URL'].split('://').last.tr('/', '_') %>.xml
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Version 0.3.0
2
+ * Added option to test all subpages and skip spellcheck
3
+
4
+ Version 0.2.3
5
+ * Put HTML report into logs folder and mention sourcing it
6
+
1
7
  Version 0.2.2
2
8
  * Ignore telephone numbers in links
3
9
 
data/README.md CHANGED
@@ -16,6 +16,18 @@ To get a log of your tests share a volume with the container.
16
16
 
17
17
  > Please share this volume from an empty folder. Running from within another gem might cause an issue
18
18
 
19
+ To test test links on all subpages of a site add `--all-subpages` to the command.
20
+
21
+ To test without performing spellchecking of common spelling add `--no-spellcheck`
22
+
23
+ E.g
24
+
25
+ `docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test --all-subpages --no-spellcheck`
26
+
27
+ You can see all options by running
28
+
29
+ `docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test help page`
30
+
19
31
  ## Add to gitlab CI for your website
20
32
 
21
33
  Add the following `YAML` to test against a website
@@ -30,7 +42,7 @@ example_test:
30
42
  artifacts:
31
43
  paths:
32
44
  - logs/*.xml
33
- - reports # HTML reports
45
+ - logs/*.html # HTML reports
34
46
  reports:
35
47
  junit: logs/*.xml
36
48
  expire_in: 1 week
data/exe/generic_test CHANGED
@@ -12,15 +12,19 @@ class Exe < Thor
12
12
  end
13
13
 
14
14
  desc 'page page_url', 'Test web page'
15
+ method_options all_subpages: false
16
+ method_options spellcheck: true
15
17
  def page(page_url)
16
18
  ENV['PAGE_URL'] = page_url
19
+ ENV['ALL_SUBPAGES'] ||= options.all_subpages?.to_s
20
+ ENV['SPELLCHECK_ON'] = options.spellcheck?.to_s
17
21
  test_file_path = File.join(File.dirname(__FILE__), '..', 'spec', 'generic_test_spec.rb')
18
22
  raise "no file at #{test_file_path}" unless File.exist? test_file_path
19
23
 
20
24
  desc = ENV['PAGE_URL'].split('://').last.tr('/', '_')
21
25
  junit_format = "-f RspecJunitFormatter --out logs/page_#{desc}.xml"
22
26
  ENV['REPORT_PATH'] = "reports/#{desc}"
23
- html_format = '--format html --out report.html'
27
+ html_format = '--format html --out logs/report.html'
24
28
  command = "rspec #{test_file_path} --format documentation --color #{junit_format} #{html_format}"
25
29
  raise $CHILD_STATUS.to_s unless system command
26
30
  end
@@ -5,6 +5,8 @@ module GenericTest
5
5
  class Page
6
6
  # @return [Array] List of links
7
7
  attr_accessor :links
8
+ # @return [Array] List of links that include domain being tested
9
+ attr_accessor :internal_links
8
10
  # @return [Array] List of emails
9
11
  attr_accessor :emails
10
12
  attr_accessor :url
@@ -18,8 +20,11 @@ module GenericTest
18
20
  self.emails, self.links = browser.links.partition do |link|
19
21
  link.href.start_with?('mailto:')
20
22
  end
21
- links.reject! { |link| link.href.empty? || link.href.start_with?('javascript:') || link.href.start_with?('tel:') }
23
+ links.reject! { |link| link.href.empty? || link.href.start_with?('javascript:') || link.href.include?('tel:') }
22
24
  emails.collect! { |link| link.href.split(':').last }
25
+ self.internal_links = links.filter do |link|
26
+ link.href.include? ENV["PAGE_URL"]
27
+ end.collect { |link| link.href }.uniq
23
28
  self.url = browser.url
24
29
  self.html = browser.html
25
30
  self.text = browser.text
@@ -34,8 +34,13 @@ if ENV[GT_LOGIN_URL] && ENV[GT_USERNAME] && ENV[GT_PASSWORD]
34
34
  puts "Login through #{ENV[GT_LOGIN_URL]} successful!"
35
35
  end
36
36
 
37
+ GenericTest.all_subpages = true if ENV['ALL_SUBPAGES'] == 'true'
37
38
  ENV['PAGE_URL'] = RestClient.get(ENV['PAGE_URL']).request.url # Check page exists
38
- puts "Checking #{ENV['PAGE_URL']}"
39
+ puts "Loading..."
39
40
  browser.goto ENV['PAGE_URL']
40
41
  sleep 2.5 # Give a bit of time for page to load
42
+ puts "Checking #{ENV['PAGE_URL']} (#{browser.title})"
41
43
  GenericTest.pages << GenericTest::Page.new(browser)
44
+ if GenericTest.all_subpages
45
+ puts "Subpages include #{GenericTest.pages.first.internal_links }"
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenericTest
4
- VERSION = '0.2.2'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/generic_test.rb CHANGED
@@ -19,7 +19,10 @@ module GenericTest
19
19
  attr_accessor :browser
20
20
  attr_accessor :pages
21
21
  attr_accessor :tested_links
22
+ # @return [Boolean]
22
23
  attr_accessor :only_javascript
24
+ # @return [Boolean] Whether to check all subpages of initial page
25
+ attr_accessor :all_subpages
23
26
  end
24
27
  end
25
28
 
@@ -10,13 +10,35 @@ RSpec.describe "#{page.title} Links respond" do
10
10
  next if GenericTest.tested_links.include? link.href
11
11
 
12
12
  GenericTest.tested_links << link.href
13
- it "Link (#{index + 1})#{link_text} to '#{link.href}' succeeds" do
14
- expect(Checker.link_status(link.href)).to be_between 200, 399
13
+ link_href = link.href
14
+ it "Link (#{GenericTest.tested_links.count})#{link_text} to '#{link.href}' succeeds" do
15
+ expect(Checker.link_status(link_href)).to be_between 200, 399
15
16
  end
16
17
  end
17
18
  puts "Checking #{GenericTest.tested_links.count} non duplicate links"
18
19
  end
19
20
 
21
+ if GenericTest.all_subpages
22
+ browser = GenericTest.browser
23
+ page.internal_links.each do |href|
24
+ browser.goto href
25
+ sub_page = GenericTest::Page.new(browser)
26
+ RSpec.describe "Subpage #{browser.title} #{href}" do
27
+ sub_page.links.each_with_index do |link, index|
28
+ link_text = link.text.to_s.empty? ? '' : " \"#{link.text}\""
29
+ next if GenericTest.tested_links.include? link.href
30
+
31
+ GenericTest.tested_links << link.href
32
+ link_href = link.href
33
+ it "Link (#{GenericTest.tested_links.count})#{link_text} to '#{link.href}' succeeds" do
34
+ expect(Checker.link_status(link_href)).to be_between 200, 399
35
+ end
36
+ end
37
+ puts "Checking #{GenericTest.tested_links.count} non duplicate links"
38
+ end
39
+ end
40
+ end
41
+
20
42
  emails = page.emails
21
43
  RSpec.describe "#{page.title} Emails are valid" do
22
44
  emails.each do |email|
@@ -26,17 +48,19 @@ RSpec.describe "#{page.title} Emails are valid" do
26
48
  end
27
49
  end
28
50
 
29
- RSpec.describe "#{page.title} Page content" do
30
- spellcheck_report = SpellCheck::ProofReader.check(page.text)
31
- context 'does not have common spelling mistakes' do
32
- it 'has no mistakes' do
33
- expect(spellcheck_report.errata.size).to eq 0
34
- end
35
- spellcheck_report.errata.group_by(&:line_number).each do |line_number, mistakes|
36
- context "Line #{line_number}" do
37
- mistakes.each_with_index do |mistake, index|
38
- it "(#{index + 1}) #{mistake.pattern}" do
39
- expect(mistake.pattern).to eq mistake.expected
51
+ if ENV['SPELLCHECK_ON'] == 'true'
52
+ RSpec.describe "#{page.title} Page content spelling" do
53
+ spellcheck_report = SpellCheck::ProofReader.check(page.text)
54
+ context 'does not have common spelling mistakes' do
55
+ it 'has no mistakes' do
56
+ expect(spellcheck_report.errata.size).to eq 0
57
+ end
58
+ spellcheck_report.errata.group_by(&:line_number).each do |line_number, mistakes|
59
+ context "Line #{line_number}" do
60
+ mistakes.each_with_index do |mistake, index|
61
+ it "(#{index + 1}) #{mistake.pattern}" do
62
+ expect(mistake.pattern).to eq mistake.expected
63
+ end
40
64
  end
41
65
  end
42
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generic_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garratt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-09 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll