generic_test 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +5 -5
- data/.rspec +1 -1
- data/ChangeLog +12 -0
- data/Dockerfile +0 -2
- data/README.md +13 -1
- data/exe/generic_test +9 -1
- data/lib/generic_test/page.rb +6 -1
- data/lib/generic_test/setup.rb +6 -1
- data/lib/generic_test/version.rb +1 -1
- data/lib/generic_test.rb +3 -0
- data/spec/generic_test_spec.rb +37 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffa3efa41fd3a9b55a1ab5a258d235dbc66a1b49140e860a0dc14fa7171d1c54
|
4
|
+
data.tar.gz: 6661eaf0388ee25e92d75d4db9a9c9cd4c30b2a3415729fb4d5679e0661cfe78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
-
|
54
|
+
- logs/*.html
|
55
55
|
reports:
|
56
56
|
junit: logs/*.xml
|
57
57
|
expire_in: 1 week
|
data/.rspec
CHANGED
data/ChangeLog
CHANGED
@@ -1,3 +1,15 @@
|
|
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
|
+
|
7
|
+
Version 0.2.2
|
8
|
+
* Ignore telephone numbers in links
|
9
|
+
|
10
|
+
Version 0.2.1
|
11
|
+
* Get working with Ruby 3.3
|
12
|
+
|
1
13
|
Version 0.1.13
|
2
14
|
* Enhancement
|
3
15
|
* Fail if cannot find url of page provided
|
data/Dockerfile
CHANGED
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
|
-
-
|
45
|
+
- logs/*.html # HTML reports
|
34
46
|
reports:
|
35
47
|
junit: logs/*.xml
|
36
48
|
expire_in: 1 week
|
data/exe/generic_test
CHANGED
@@ -7,16 +7,24 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
7
7
|
|
8
8
|
# Executable for Generic Test
|
9
9
|
class Exe < Thor
|
10
|
+
def self.exit_on_failure?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
10
14
|
desc 'page page_url', 'Test web page'
|
15
|
+
method_options all_subpages: false
|
16
|
+
method_options spellcheck: true
|
11
17
|
def page(page_url)
|
12
18
|
ENV['PAGE_URL'] = page_url
|
19
|
+
ENV['ALL_SUBPAGES'] ||= options.all_subpages?.to_s
|
20
|
+
ENV['SPELLCHECK_ON'] = options.spellcheck?.to_s
|
13
21
|
test_file_path = File.join(File.dirname(__FILE__), '..', 'spec', 'generic_test_spec.rb')
|
14
22
|
raise "no file at #{test_file_path}" unless File.exist? test_file_path
|
15
23
|
|
16
24
|
desc = ENV['PAGE_URL'].split('://').last.tr('/', '_')
|
17
25
|
junit_format = "-f RspecJunitFormatter --out logs/page_#{desc}.xml"
|
18
26
|
ENV['REPORT_PATH'] = "reports/#{desc}"
|
19
|
-
html_format = '--format html --out report.html'
|
27
|
+
html_format = '--format html --out logs/report.html'
|
20
28
|
command = "rspec #{test_file_path} --format documentation --color #{junit_format} #{html_format}"
|
21
29
|
raise $CHILD_STATUS.to_s unless system command
|
22
30
|
end
|
data/lib/generic_test/page.rb
CHANGED
@@ -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:') }
|
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
|
data/lib/generic_test/setup.rb
CHANGED
@@ -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 "
|
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
|
data/lib/generic_test/version.rb
CHANGED
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
|
|
data/spec/generic_test_spec.rb
CHANGED
@@ -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
|
-
|
14
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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.
|
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-
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|