generic_test 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +8 -1
- data/.rspec +2 -1
- data/ChangeLog +10 -0
- data/Dockerfile +1 -3
- data/README.md +4 -0
- data/exe/generic_test +7 -3
- data/generic_test.gemspec +1 -0
- data/lib/generic_test/checker.rb +28 -1
- data/lib/generic_test/version.rb +1 -1
- data/lib/generic_test.rb +4 -0
- data/spec/generic_test_spec.rb +6 -2
- data/spec/test_gem_spec.rb +11 -9
- data/test_site/index.html +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f9ac47ef59a74ef5217ab7799c57018405be18fbbe6dfce6c2c04d050353283
|
4
|
+
data.tar.gz: 93079f38f519161351ebcc12d5dd03a5ef07a47fdc34b2c5ff3632a0a3d0b85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 625ffb51903fc52a6c9b3c07be6e03995c3674c041e90a13d2b6f8fd553a6ca9f28975d10e6d67f95e5fb7b43fb9a9ccb099ad7b6ec40bd35c53181ebeac9908
|
7
|
+
data.tar.gz: 458b701efb701fd57fb624451117e8006cb8365bcbfb7f53b00d75ba91af3742f7b2c239d5cc37626e8b25e71187e50eee45c50a3cc204a445435c90abbe2d10
|
data/.gitignore
CHANGED
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: test
|
12
12
|
services:
|
13
13
|
- docker:19.03.5-dind
|
14
14
|
image: docker:19.03.5
|
@@ -26,6 +26,13 @@ test:
|
|
26
26
|
- gem install bundler
|
27
27
|
- bundle install
|
28
28
|
- bundle exec rake
|
29
|
+
artifacts:
|
30
|
+
paths:
|
31
|
+
- logs/*.xml
|
32
|
+
reports:
|
33
|
+
junit: logs/*.xml
|
34
|
+
expire_in: 1 week
|
35
|
+
when: always
|
29
36
|
|
30
37
|
pages:
|
31
38
|
stage: deploy
|
data/.rspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
--format documentation
|
2
2
|
--color
|
3
3
|
--require spec_helper
|
4
|
-
--format RspecJunitFormatter --out logs/page_<%= ENV['PAGE_URL'].split('://').last %>.xml
|
4
|
+
--format RspecJunitFormatter --out logs/page_<%= ENV['PAGE_URL'].split('://').last.tr('/', '_') %>.xml
|
5
|
+
--format RspecHtmlReporter
|
data/ChangeLog
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
Version 0.1.7
|
2
|
+
* Enhancement
|
3
|
+
* Running generic_test exe yield correct status code on failure
|
4
|
+
* Add RSpec HTML report
|
5
|
+
* Put rest-client back in for addresses failing via Javascript
|
6
|
+
|
7
|
+
Version 0.1.6
|
8
|
+
* Enhancement
|
9
|
+
* Junit xml path not have subfolder for easier inclusion in test results
|
10
|
+
|
1
11
|
Version 0.1.5
|
2
12
|
* Enhancement
|
3
13
|
* Add Junit formatter
|
data/Dockerfile
CHANGED
@@ -4,9 +4,7 @@ MAINTAINER Samuel Garratt
|
|
4
4
|
# Required ruby gems
|
5
5
|
RUN mkdir /test
|
6
6
|
WORKDIR /test
|
7
|
-
RUN gem install
|
8
|
-
# Should be able to be removed once gem published with dev depdencies
|
9
|
-
RUN gem install jekyll rake
|
7
|
+
RUN gem install generic_test
|
10
8
|
|
11
9
|
# Google chrome
|
12
10
|
ARG CHROME_VERSION="google-chrome-stable"
|
data/README.md
CHANGED
@@ -8,6 +8,10 @@ Run test gem through docker against this with
|
|
8
8
|
|
9
9
|
`docker run -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test`
|
10
10
|
|
11
|
+
To get a log of your tests share a volume with the container
|
12
|
+
|
13
|
+
`docker run -v "$PWD":/test -t registry.gitlab.com/samuel-garratt/generic_test generic_test page samuel-garratt.gitlab.io/generic_test`
|
14
|
+
|
11
15
|
## Installation
|
12
16
|
|
13
17
|
Add this line to your application's Gemfile:
|
data/exe/generic_test
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'thor'
|
5
|
+
require 'English'
|
5
6
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
6
7
|
|
7
8
|
# Executable for Generic Test
|
@@ -12,9 +13,12 @@ class Exe < Thor
|
|
12
13
|
test_file_path = File.join(File.dirname(__FILE__), '..', 'spec', 'generic_test_spec.rb')
|
13
14
|
raise "no file at #{test_file_path}" unless File.exist? test_file_path
|
14
15
|
|
15
|
-
desc = ENV['PAGE_URL'].split('://').last
|
16
|
-
|
17
|
-
|
16
|
+
desc = ENV['PAGE_URL'].split('://').last.tr('/', '_')
|
17
|
+
junit_format = "-f RspecJunitFormatter --out logs/page_#{desc}.xml"
|
18
|
+
ENV['REPORT_PATH'] = "reports/#{desc}"
|
19
|
+
html_format = "-f RspecHtmlReporter"
|
20
|
+
command = "rspec #{test_file_path} --format documentation --color #{junit_format} #{html_format}"
|
21
|
+
raise $CHILD_STATUS.to_s unless system command
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
data/generic_test.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'jekyll' # For hosting test website
|
30
30
|
spec.add_dependency 'rake'
|
31
31
|
|
32
|
+
spec.add_dependency 'rest-client'
|
32
33
|
spec.add_dependency 'rspec'
|
33
34
|
spec.add_dependency 'rspec_html_reporter' # Pretty HTML reports
|
34
35
|
spec.add_dependency 'rspec_junit_formatter' # Needed for nicer reporting of rspec for use in Gitlab
|
data/lib/generic_test/checker.rb
CHANGED
@@ -1,12 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
|
1
5
|
# Module for checking parts on a site
|
2
6
|
module Checker
|
3
7
|
class << self
|
8
|
+
def valid_link?(href)
|
9
|
+
!href.start_with?('mailto:')
|
10
|
+
end
|
11
|
+
|
12
|
+
# Usign Javascript fetch to retrieve URL. See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch and
|
13
|
+
# https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters for details
|
4
14
|
# @return [Integer] Status code
|
5
15
|
def link_status(href)
|
6
|
-
|
16
|
+
init_options = "const myInit = {
|
17
|
+
method: 'GET',
|
18
|
+
credentials: 'same-origin',
|
19
|
+
cache: 'default',
|
20
|
+
mode: 'cors'
|
21
|
+
};"
|
22
|
+
get_js_code = "var url='#{href}'; #{init_options} return fetch(url, myInit).then(res=>{return res.status});"
|
7
23
|
GenericTest.browser.execute_script get_js_code
|
8
24
|
rescue Selenium::WebDriver::Error::JavascriptError
|
25
|
+
return call_via_rest_client(href) unless GenericTest.only_javascript
|
26
|
+
|
9
27
|
raise GenericTest::Error, "Failed to fetch url '#{href}'"
|
10
28
|
end
|
29
|
+
|
30
|
+
# Use rest-client to try and get status of URL
|
31
|
+
def call_via_rest_client(href)
|
32
|
+
RestClient.get(href).code
|
33
|
+
rescue RestClient::Exception => e
|
34
|
+
return e.response&.code if e.respond_to? :response
|
35
|
+
|
36
|
+
raise e
|
37
|
+
end
|
11
38
|
end
|
12
39
|
end
|
data/lib/generic_test/version.rb
CHANGED
data/lib/generic_test.rb
CHANGED
@@ -10,10 +10,14 @@ require 'webdrivers'
|
|
10
10
|
module GenericTest
|
11
11
|
class Error < StandardError; end
|
12
12
|
@pages = []
|
13
|
+
# @return [Boolean] Whether to only use Javascript. RestClient won't run in same context as
|
14
|
+
# browser so less likely to be accurate for logged in pages
|
15
|
+
@only_javascript = false
|
13
16
|
|
14
17
|
class << self
|
15
18
|
attr_accessor :browser
|
16
19
|
attr_accessor :pages
|
20
|
+
attr_accessor :only_javascript
|
17
21
|
|
18
22
|
def setup
|
19
23
|
ENV['HEADLESS'] ||= 'true'
|
data/spec/generic_test_spec.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'generic_test/setup'
|
3
4
|
page = GenericTest.pages.first
|
4
5
|
links = page.links
|
5
6
|
RSpec.describe "#{page.title} Links respond" do
|
6
7
|
links.each_with_index do |link, index|
|
7
8
|
next unless link.href && !link.href.empty?
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
link_text = link.text.to_s.empty? ? '' : " \"#{link.text}\""
|
11
|
+
it "Link (#{index + 1})#{link_text} to '#{link.href}' succeeds" do
|
12
|
+
if Checker.valid_link? link.href
|
13
|
+
expect(Checker.link_status(link.href)).to be_between 200, 399
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/spec/test_gem_spec.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Test gem works internally
|
2
4
|
|
3
|
-
GenericTest.pages.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
page = GenericTest.pages.first
|
6
|
+
links = page.links
|
7
|
+
puts links.collect(&:text)
|
8
|
+
RSpec.describe 'Links respond' do
|
9
|
+
it 'successful link passes' do
|
10
|
+
expect(Checker.link_status(links[0].href)).to be_between 200, 399
|
11
|
+
end
|
12
|
+
it 'broken link causes failure' do
|
13
|
+
expect(Checker.link_status(links[1].href)).to eq 404
|
12
14
|
end
|
13
15
|
end
|
data/test_site/index.html
CHANGED
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.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garratt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|