generic_test 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +2 -0
- data/.gitlab-ci.yml +1 -1
- data/ChangeLog +3 -0
- data/Dockerfile +6 -14
- data/Rakefile +3 -3
- data/exe/generic_test +1 -2
- data/generic_test.gemspec +1 -1
- data/lib/generic_test.rb +3 -0
- data/lib/generic_test/checker.rb +6 -1
- data/lib/generic_test/page.rb +11 -4
- data/lib/generic_test/version.rb +1 -1
- data/spec/generic_test_spec.rb +17 -0
- data/spec/spec_helper.rb +1 -6
- data/spec/test_gem_spec.rb +1 -3
- data/test_site/about.html +2 -0
- data/test_site/index.html +19 -0
- metadata +5 -5
- data/run.sh +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd51ef58653e170a434b60dc60b963cdb38ca248ffe8c7ad5cdcb290b3ae8d4
|
4
|
+
data.tar.gz: e51eef767608a111aa1c119ea367ab5bf159cd072f6c4c3015cc588f2e938c46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bada0281d88dce8ec44033d833c2df8e974cda38e0040bdfc3081f5987607955591588b36f9c59a556f32f3462063798ba5dbcda2635262b606ccf285c96bc42
|
7
|
+
data.tar.gz: 47c446ca6abd2eabf63bf332c2918b3f13590f8ad1c4a29bbc888c965613f59effe9d539e27d8d4c9c8b1583c8186118af5bcc9dfe3a7a5f260a7c899c484cf0
|
data/.dockerignore
ADDED
data/.gitlab-ci.yml
CHANGED
data/ChangeLog
CHANGED
data/Dockerfile
CHANGED
@@ -2,19 +2,9 @@ FROM ruby:2.6
|
|
2
2
|
MAINTAINER Samuel Garratt
|
3
3
|
|
4
4
|
# Required ruby gems
|
5
|
-
RUN mkdir /
|
6
|
-
WORKDIR /
|
7
|
-
|
8
|
-
RUN gem install bundler
|
9
|
-
RUN bundle install
|
10
|
-
# Install gem within itself
|
11
|
-
RUN rake install
|
12
|
-
|
13
|
-
# Virtual Frame buffer
|
14
|
-
RUN apt-get update -y \
|
15
|
-
&& apt-get -y install \
|
16
|
-
xvfb \
|
17
|
-
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
|
5
|
+
RUN mkdir /test
|
6
|
+
WORKDIR /test
|
7
|
+
RUN gem install generic_test
|
18
8
|
|
19
9
|
# Google chrome
|
20
10
|
ARG CHROME_VERSION="google-chrome-stable"
|
@@ -29,4 +19,6 @@ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key
|
|
29
19
|
# Add language settings to handle special characters
|
30
20
|
RUN export LANG=C.UTF-8
|
31
21
|
RUN export LANGUAGE=C.UTF-8
|
32
|
-
RUN export LC_ALL=C.UTF-8
|
22
|
+
RUN export LC_ALL=C.UTF-8
|
23
|
+
# By running test image is checked and webdriver will be cached
|
24
|
+
RUN generic_test page samuel-garratt.gitlab.io/generic_test/about.html
|
data/Rakefile
CHANGED
@@ -12,11 +12,11 @@ directory 'logs'
|
|
12
12
|
desc 'Start virtual web service'
|
13
13
|
task start_website: :logs do
|
14
14
|
mkdir_p 'logs'
|
15
|
-
|
16
|
-
|
15
|
+
ENV['test_site_pid'] = Process.spawn('jekyll', 'serve', '-s', 'test_site',
|
16
|
+
err: %w[logs/test_site.log w]).to_s
|
17
17
|
sleep 2 # Wait a little for virtual server to start up
|
18
18
|
puts 'Running test site on pid ' + ENV['test_site_pid']
|
19
|
-
ENV['PAGE_URL'] = '
|
19
|
+
ENV['PAGE_URL'] = 'http://127.0.0.1:4000'
|
20
20
|
end
|
21
21
|
|
22
22
|
task default: :spec
|
data/exe/generic_test
CHANGED
@@ -4,13 +4,12 @@
|
|
4
4
|
require 'thor'
|
5
5
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
6
6
|
require 'generic_test'
|
7
|
-
|
7
|
+
|
8
8
|
# Executable for Generic Test
|
9
9
|
class Exe < Thor
|
10
10
|
desc 'page page_url', 'Test web page'
|
11
11
|
def page(page_url)
|
12
12
|
ENV['PAGE_URL'] = page_url
|
13
|
-
puts ENV['PAGE_URL']
|
14
13
|
system "cd #{File.join(File.dirname(__FILE__), '..')} && rspec spec/generic_test_spec.rb"
|
15
14
|
end
|
16
15
|
end
|
data/generic_test.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.bindir = 'exe'
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
|
-
spec.add_dependency 'rest-client'
|
29
28
|
spec.add_dependency 'rspec'
|
29
|
+
spec.add_dependency 'spellcheck'
|
30
30
|
spec.add_dependency 'thor' # Command line utility
|
31
31
|
spec.add_dependency 'watir' # UI interaction
|
32
32
|
spec.add_dependency 'webdrivers' # Download chromedriver
|
data/lib/generic_test.rb
CHANGED
data/lib/generic_test/checker.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
# Module for checking parts on a site
|
1
2
|
module Checker
|
2
3
|
class << self
|
4
|
+
# @return [Integer] Status code
|
3
5
|
def link_status(href)
|
4
|
-
|
6
|
+
get_js_code = "var url='#{href}'; return fetch(url).then(res=>{return res.status});"
|
7
|
+
GenericTest.browser.execute_script get_js_code
|
8
|
+
rescue Selenium::WebDriver::Error::JavascriptError
|
9
|
+
raise GenericTest::Error, "Failed to fetch url '#{href}'"
|
5
10
|
end
|
6
11
|
end
|
7
12
|
end
|
data/lib/generic_test/page.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
module GenericTest
|
2
|
+
# Represents a web page state at a particular point of time
|
2
3
|
class Page
|
3
4
|
# @return [Array] List of links
|
4
5
|
attr_accessor :links
|
5
6
|
attr_accessor :url
|
7
|
+
attr_accessor :html
|
8
|
+
attr_accessor :title
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
# Store state of page when it is loaded
|
11
|
+
# @param [Watir::Browser] browser Watir browser
|
12
|
+
def initialize(browser)
|
13
|
+
self.links = browser.links
|
14
|
+
self.url = browser.url
|
15
|
+
self.html = browser.html
|
16
|
+
self.title = browser.title
|
17
|
+
puts "Found #{links.count} links at #{url} (#{title})"
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
data/lib/generic_test/version.rb
CHANGED
data/spec/generic_test_spec.rb
CHANGED
@@ -11,4 +11,21 @@ GenericTest.pages.each do |page|
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
+
RSpec.describe 'Page content' do
|
15
|
+
spellcheck_report = SpellCheck::ProofReader.check(page.html)
|
16
|
+
context 'does not have common spelling mistakes' do
|
17
|
+
it 'has no mistakes' do
|
18
|
+
expect(spellcheck_report.status).to eq 'Accept'
|
19
|
+
end
|
20
|
+
spellcheck_report.errata.group_by(&:line_number).each do |line_number, mistakes|
|
21
|
+
context "Line #{line_number}" do
|
22
|
+
mistakes.each_with_index do |mistake, index|
|
23
|
+
it "(#{index + 1}) #{mistake.pattern}" do
|
24
|
+
expect(mistake.pattern).to eq mistake.expected
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
14
31
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'generic_test'
|
5
|
-
require 'rest-client'
|
6
|
-
require 'watir'
|
7
|
-
require 'webdrivers'
|
8
5
|
|
9
6
|
ENV['HEADLESS'] ||= 'true'
|
10
7
|
browser_args = %w[--disable-popup-blocking --no-sandbox --disable-dev-shm-usage]
|
@@ -14,9 +11,7 @@ GenericTest.browser = Watir::Browser.new :chrome, args: browser_args
|
|
14
11
|
|
15
12
|
browser = GenericTest.browser
|
16
13
|
browser.goto ENV['PAGE_URL']
|
17
|
-
|
18
|
-
links = browser.links
|
19
|
-
GenericTest.pages << GenericTest::Page.new(ENV['PAGE_URL'], links)
|
14
|
+
GenericTest.pages << GenericTest::Page.new(browser)
|
20
15
|
|
21
16
|
RSpec.configure do |config|
|
22
17
|
# Close test server after all RSpec tests have run
|
data/spec/test_gem_spec.rb
CHANGED
@@ -7,9 +7,7 @@ GenericTest.pages.each do |page|
|
|
7
7
|
expect(Checker.link_status(links[0].href)).to be_between 200, 399
|
8
8
|
end
|
9
9
|
it 'broken link causes failure' do
|
10
|
-
expect
|
11
|
-
Checker.link_status(links[1].href)
|
12
|
-
end.to raise_error RestClient::NotFound
|
10
|
+
expect(Checker.link_status(links[1].href)).to eq 404
|
13
11
|
end
|
14
12
|
end
|
15
13
|
end
|
data/test_site/about.html
CHANGED
data/test_site/index.html
CHANGED
@@ -12,5 +12,24 @@
|
|
12
12
|
<p id="broken_link">
|
13
13
|
<a href="broken_link.html">Broken link</a>
|
14
14
|
</p>
|
15
|
+
<p>hello world.
|
16
|
+
|
17
|
+
I create aplication now.
|
18
|
+
|
19
|
+
good bye
|
20
|
+
|
21
|
+
dokcer is great tool.
|
22
|
+
|
23
|
+
```
|
24
|
+
bunlde intall ruby-build
|
25
|
+
```
|
26
|
+
|
27
|
+
sample smaple
|
28
|
+
|
29
|
+
smaple sample
|
30
|
+
|
31
|
+
This is a smaple mistake
|
32
|
+
pakcage
|
33
|
+
</p>
|
15
34
|
</body>
|
16
35
|
</html>
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
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.1
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: spellcheck
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -88,6 +88,7 @@ executables:
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".dockerignore"
|
91
92
|
- ".gitignore"
|
92
93
|
- ".gitlab-ci.yml"
|
93
94
|
- ".rspec"
|
@@ -106,7 +107,6 @@ files:
|
|
106
107
|
- lib/generic_test/checker.rb
|
107
108
|
- lib/generic_test/page.rb
|
108
109
|
- lib/generic_test/version.rb
|
109
|
-
- run.sh
|
110
110
|
- spec/generic_test_spec.rb
|
111
111
|
- spec/spec_helper.rb
|
112
112
|
- spec/test_gem_spec.rb
|
data/run.sh
DELETED