generic_test 0.1.9 → 0.1.10

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: 240386cd484ae65d67e46c29f9534eb17bc88f5e198bfabf34b689babad38038
4
- data.tar.gz: 76c74899bef89a6a2cd856d6b6e1f4db154443f09427fa7c259e9a3f602b0410
3
+ metadata.gz: 3cd6c9a3fb72be1be7624ef067e5240d37cd95607a62f1a18214de73e589be63
4
+ data.tar.gz: ee175d1814512d5dfb07582dd733e06525e7b3c324c42a9922e6eb50cf69b33f
5
5
  SHA512:
6
- metadata.gz: 710883182d9f0aaa0d81f19f744edfd1b8abadb9e703ac7c53235464046f5b8c53044e7fd4ba211471963a2ec8732511d44b1b7a67daea17296342aac8a44a76
7
- data.tar.gz: '0093ddc398d3101d2957fa9c883e3a97e52b3730e59b33f8592042c1c345a44f10c067a96e14dd5ce7c406bff63436f77ce72375be30d96b4d3b64b04b2cf8c8'
6
+ metadata.gz: 8c6f165cba804d210657ef544a83da5de6bb21b664ea446b18f87ba817b0fdcc29ca80883518427a1ffc5b3ea4117271ecf65290bbdb0134115657577da373d3
7
+ data.tar.gz: a960a256ecbd5d8c951458936323c8e8a55ef5c4855a614f21fa29adda402b191e265adfe3de7ba62700568ee831bee9b3c2ba92efd9be2e1b90b24a8620ecd8
data/.gitlab-ci.yml CHANGED
@@ -8,13 +8,13 @@ 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
11
+ stage: deploy # Part of a later stage
12
12
  services:
13
13
  - docker:19.03.5-dind
14
14
  image: docker:19.03.5
15
15
  script:
16
16
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
17
- - docker pull $CI_REGISTRY_IMAGE:latest || true
17
+ - docker pull --quiet $CI_REGISTRY_IMAGE:latest || true
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
data/ChangeLog CHANGED
@@ -1,6 +1,11 @@
1
+ Version 0.1.10
2
+ * Bug fix
3
+ * Add custom file implementing mock of what's needed for RSpecHtmlReporter
4
+ * Split email addresses into separate list and add validation for them using 'email_address' gem
5
+
1
6
  Version 0.1.9
2
7
  * Bug fix
3
- * rspec-legacy_formatters now needed for RSpecHtmlFormatter
8
+ * rspec-legacy_formatters will be needed for RSpecHtmlFormatter
4
9
 
5
10
  Version 0.1.8
6
11
  * Bug fix
data/Dockerfile CHANGED
@@ -4,7 +4,7 @@ MAINTAINER Samuel Garratt
4
4
  # Required ruby gems
5
5
  RUN mkdir /test
6
6
  WORKDIR /test
7
- RUN gem install generic_test
7
+ RUN gem install bundler generic_test
8
8
 
9
9
  # Google chrome
10
10
  ARG CHROME_VERSION="google-chrome-stable"
data/README.md CHANGED
@@ -4,7 +4,7 @@ This gem provides an easy way to run generic tests for a website/api
4
4
 
5
5
  Test site is at https://samuel-garratt.gitlab.io/generic_test
6
6
 
7
- Run test gem through docker against this with
7
+ Run test gem through docker against this website with (Note it is an example that has some failures)
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
 
data/exe/generic_test CHANGED
@@ -16,10 +16,16 @@ class Exe < Thor
16
16
  desc = ENV['PAGE_URL'].split('://').last.tr('/', '_')
17
17
  junit_format = "-f RspecJunitFormatter --out logs/page_#{desc}.xml"
18
18
  ENV['REPORT_PATH'] = "reports/#{desc}"
19
- html_format = '--require rspec_html_reporter -f RspecHtmlReporter'
19
+ html_format = '--require generic_test/html_reporter -f RspecHtmlReporter'
20
20
  command = "rspec #{test_file_path} --format documentation --color #{junit_format} #{html_format}"
21
21
  raise $CHILD_STATUS.to_s unless system command
22
22
  end
23
+
24
+ desc 'version', 'Version of generic_test'
25
+ def version
26
+ require 'generic_test'
27
+ puts "GenericTest version #{GenericTest::VERSION}"
28
+ end
23
29
  end
24
30
 
25
31
  Exe.start(ARGV)
data/generic_test.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = 'https://gitlab.com/samuel-garratt/generic_test'
18
- spec.metadata['changelog_uri'] = 'https://gitlab.com/samuel-garratt/soaspec/blob/master/ChangeLog'
18
+ spec.metadata['changelog_uri'] = 'https://gitlab.com/samuel-garratt/generic_test/blob/master/ChangeLog'
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -27,15 +27,17 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ['lib']
28
28
  # Development dependencies are installed too since running external tests within gem
29
29
  spec.add_development_dependency 'jekyll' # For hosting test website
30
- spec.add_dependency 'rake'
31
-
32
- spec.add_dependency 'rest-client'
33
- spec.add_dependency 'rspec'
30
+ spec.add_development_dependency 'rake'
34
31
  spec.add_dependency 'rspec-legacy_formatters' # Needed for rspec_html_reporter after RSpec 3
35
- spec.add_dependency 'rspec_html_reporter' # Pretty HTML reports
36
- spec.add_dependency 'rspec_junit_formatter' # Needed for nicer reporting of rspec for use in Gitlab
37
- spec.add_dependency 'spellcheck'
38
- spec.add_dependency 'thor' # Command line utility
39
- spec.add_dependency 'watir' # UI interaction
40
- spec.add_dependency 'webdrivers' # Download chromedriver
32
+ spec.add_dependency 'rspec_html_reporter' # Pretty HTML reports
33
+ spec.add_dependency 'rspec_junit_formatter' # Needed for nicer reporting of rspec for use in CI
34
+ spec.add_dependency 'simplecov' # Code coverage
35
+
36
+ spec.add_dependency 'email_address' # Verify email address
37
+ spec.add_dependency 'rest-client' # Verify links
38
+ spec.add_dependency 'rspec' # Test framework
39
+ spec.add_dependency 'spellcheck' # Check for common spelling errors
40
+ spec.add_dependency 'thor' # Command line utility
41
+ spec.add_dependency 'watir' # UI interaction
42
+ spec.add_dependency 'webdrivers' # Download chromedriver automatically
41
43
  end
@@ -1,18 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rest-client'
4
+ require 'email_address'
4
5
 
5
6
  # Module for checking parts on a site
6
7
  module Checker
7
8
  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
9
+ # Using Javascript fetch to retrieve URL. See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch and
13
10
  # https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters for details
14
11
  # @return [Integer] Status code
15
12
  def link_status(href)
13
+ return unless href
14
+
16
15
  init_options = "const myInit = {
17
16
  method: 'GET',
18
17
  credentials: 'same-origin',
@@ -27,6 +26,11 @@ module Checker
27
26
  raise GenericTest::Error, "Failed to fetch url '#{href}'"
28
27
  end
29
28
 
29
+ # @return [Nil, String] Nil if valid, string if error
30
+ def valid_email?(email_address)
31
+ EmailAddress.error email_address
32
+ end
33
+
30
34
  # Use rest-client to try and get status of URL
31
35
  def call_via_rest_client(href)
32
36
  RestClient.get(href).code
@@ -0,0 +1,11 @@
1
+ # Mock implementation of Bundler for use by generic_test where Bundler.root is needed
2
+ module Bundler
3
+ class << self
4
+ # Used just so that RSpecHtmlReporter does not thrown an error
5
+ def root
6
+ ''
7
+ end
8
+ end
9
+ end
10
+
11
+ require 'rspec_html_reporter'
@@ -3,6 +3,8 @@ module GenericTest
3
3
  class Page
4
4
  # @return [Array] List of links
5
5
  attr_accessor :links
6
+ # @return [Array] List of emails
7
+ attr_accessor :emails
6
8
  attr_accessor :url
7
9
  attr_accessor :html
8
10
  attr_accessor :title
@@ -10,11 +12,15 @@ module GenericTest
10
12
  # Store state of page when it is loaded
11
13
  # @param [Watir::Browser] browser Watir browser
12
14
  def initialize(browser)
13
- self.links = browser.links
15
+ self.emails, self.links = browser.links.partition do |link|
16
+ link.href.start_with?('mailto:')
17
+ end
18
+ links.reject! { |link| link.href.empty? }
19
+ emails.collect! { |link| link.href.split(':').last }
14
20
  self.url = browser.url
15
21
  self.html = browser.html
16
22
  self.title = browser.title
17
- puts "Found #{links.count} links at #{url} (#{title})"
23
+ puts "Found #{links.count} links, #{emails.count} emails at #{url} (#{title})"
18
24
  end
19
25
  end
20
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenericTest
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
@@ -1,25 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Used by executable to verify a particular web page
3
4
  require 'generic_test/setup'
4
5
  page = GenericTest.pages.first
5
6
  links = page.links
6
7
  RSpec.describe "#{page.title} Links respond" do
7
8
  links.each_with_index do |link, index|
8
- next unless link.href && !link.href.empty?
9
-
10
9
  link_text = link.text.to_s.empty? ? '' : " \"#{link.text}\""
11
10
  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
+ expect(Checker.link_status(link.href)).to be_between 200, 399
15
12
  end
16
13
  end
17
14
  end
15
+
16
+ emails = page.emails
17
+ RSpec.describe "#{page.title} Emails are valid" do
18
+ emails.each do |email|
19
+ it "Email (#{email}) is valid" do
20
+ expect(Checker.valid_email?(email)).to be nil
21
+ end
22
+ end
23
+ end
24
+
18
25
  RSpec.describe "#{page.title} Page content" do
19
26
  spellcheck_report = SpellCheck::ProofReader.check(page.html)
20
27
  context 'does not have common spelling mistakes' do
21
28
  it 'has no mistakes' do
22
- expect(spellcheck_report.status).to eq 'Accept'
29
+ expect(spellcheck_report.errata.size).to eq 0
23
30
  end
24
31
  spellcheck_report.errata.group_by(&:line_number).each do |line_number, mistakes|
25
32
  context "Line #{line_number}" do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/setup'
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter 'spec'
7
+ end
8
+
9
+ SimpleCov.at_exit do
10
+ SimpleCov.result.format!
11
+ SimpleCov.minimum_coverage 85
12
+ end
13
+
4
14
  require 'generic_test/setup'
5
15
 
6
16
  RSpec.configure do |config|
@@ -1,15 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Test gem works internally
3
+ # Test gem works
4
4
 
5
5
  page = GenericTest.pages.first
6
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
7
+
8
+ RSpec.describe 'Links' do
9
+ it 'counts correctly (not include )' do
10
+ expect(links.size).to eq 3
11
+ end
12
+ context 'successful' do
13
+ it 'external page' do
14
+ expect(Checker.link_status(links[0].href)).to be_between 200, 399
15
+ end
16
+ it 'internal link' do
17
+ expect(Checker.link_status(links[2].href)).to be_between 200, 399
18
+ end
11
19
  end
12
- it 'broken link causes failure' do
20
+ it 'broken causes failure' do
13
21
  expect(Checker.link_status(links[1].href)).to eq 404
14
22
  end
15
23
  end
24
+ puts page.emails
25
+ RSpec.describe 'Emails' do
26
+ it 'counts correctly' do
27
+ expect(page.emails.size).to eq 2
28
+ end
29
+ context 'validate' do
30
+ it 'accepts valid email' do
31
+ expect(Checker.valid_email?(page.emails[0])).to be nil
32
+ end
33
+ it 'returns invalid email error' do
34
+ expect(Checker.valid_email?(page.emails[1])).to eq 'Domain name not registered'
35
+ end
36
+ end
37
+ end
data/test_site/index.html CHANGED
@@ -12,6 +12,12 @@
12
12
  <p id="broken_link">
13
13
  <a href="broken_link.html">Broken link</a>
14
14
  </p>
15
+ <h2><a id="special_links"></a> Special links</h2>
16
+ <p>
17
+ <a href="mailto:samuel.garratt@integrationqa.com">Email me</a>
18
+ <a href="#special_links">Link to heading</a>
19
+ <a href="mailto:invalid.person@bad-d0main.com">Don't try to email this</a>
20
+ </p>
15
21
  <p>hello world.
16
22
 
17
23
  I create aplication now.
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.9
4
+ version: 0.1.10
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-17 00:00:00.000000000 Z
11
+ date: 2020-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -26,6 +26,20 @@ dependencies:
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-legacy_formatters
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rest-client
56
+ name: rspec_html_reporter
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rspec
70
+ name: rspec_junit_formatter
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rspec-legacy_formatters
84
+ name: simplecov
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: rspec_html_reporter
98
+ name: email_address
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,7 +109,21 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: rspec_junit_formatter
112
+ name: rest-client
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -189,6 +217,7 @@ files:
189
217
  - generic_test.gemspec
190
218
  - lib/generic_test.rb
191
219
  - lib/generic_test/checker.rb
220
+ - lib/generic_test/html_reporter.rb
192
221
  - lib/generic_test/page.rb
193
222
  - lib/generic_test/setup.rb
194
223
  - lib/generic_test/version.rb
@@ -203,7 +232,7 @@ licenses:
203
232
  metadata:
204
233
  homepage_uri: https://gitlab.com/samuel-garratt/generic_test
205
234
  source_code_uri: https://gitlab.com/samuel-garratt/generic_test
206
- changelog_uri: https://gitlab.com/samuel-garratt/soaspec/blob/master/ChangeLog
235
+ changelog_uri: https://gitlab.com/samuel-garratt/generic_test/blob/master/ChangeLog
207
236
  post_install_message:
208
237
  rdoc_options: []
209
238
  require_paths: