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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db48df4cfd4cd3d8c19c7678a1c6055ce2d445ab6b9537762ee7376e96abe639
4
- data.tar.gz: 1085e7d52b22cdd9df1b979118645bff5454bf30038335182ac20d071dccd7b9
3
+ metadata.gz: 5f9ac47ef59a74ef5217ab7799c57018405be18fbbe6dfce6c2c04d050353283
4
+ data.tar.gz: 93079f38f519161351ebcc12d5dd03a5ef07a47fdc34b2c5ff3632a0a3d0b85d
5
5
  SHA512:
6
- metadata.gz: f6a91b9bde9af86eb671a9441da34f0f64bd4b3b958754f01fc77096d3906093bffb30f5500dc8b1289b9c857d219e5f538f8d1d8e6024064ddd202a72cb22c2
7
- data.tar.gz: dfeeec46979ed84bb0e0c5fa8925daf6951016cc7755dafc12544b71c298e252d509e259063ec4fd8ee2bd4fc59192532aca8d337bfbe989bb8d5108657bacdb
6
+ metadata.gz: 625ffb51903fc52a6c9b3c07be6e03995c3674c041e90a13d2b6f8fd553a6ca9f28975d10e6d67f95e5fb7b43fb9a9ccb099ad7b6ec40bd35c53181ebeac9908
7
+ data.tar.gz: 458b701efb701fd57fb624451117e8006cb8365bcbfb7f53b00d75ba91af3742f7b2c239d5cc37626e8b25e71187e50eee45c50a3cc204a445435c90abbe2d10
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /reports/
8
9
  /tmp/
9
10
  /.idea/
10
11
  /_site/
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: build
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 bundler generic_test
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
- command = "rspec #{test_file_path} --format documentation --require generic_test/setup --color --format RspecJunitFormatter --out logs/page_#{desc}.xml"
17
- system command
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
@@ -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
- get_js_code = "var url='#{href}'; return fetch(url).then(res=>{return res.status});"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenericTest
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.7'
5
5
  end
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'
@@ -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
- it "Link (#{index + 1}) \"#{link.text}\" to '#{link.href}' responds" do
10
- expect(Checker.link_status(link.href)).to be_between 200, 399
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
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Test gem works internally
2
4
 
3
- GenericTest.pages.each do |page|
4
- links = page.links
5
- RSpec.describe 'Links respond' do
6
- it 'successful link passes' do
7
- expect(Checker.link_status(links[0].href)).to be_between 200, 399
8
- end
9
- it 'broken link causes failure' do
10
- expect(Checker.link_status(links[1].href)).to eq 404
11
- end
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
@@ -1,4 +1,4 @@
1
- <html>
1
+ <html lang="en">
2
2
  <head>
3
3
  <title>Index</title>
4
4
  </head>
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.5
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-15 00:00:00.000000000 Z
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