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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b24968d52699e3323d8dae288b3013aa10a699f996999b9a8d5fecbd828ec415
4
- data.tar.gz: ed18d73c538f5d41ba41588d4bef8019238106a1a0f578e1e4dc2c8420bf20b8
3
+ metadata.gz: ddd51ef58653e170a434b60dc60b963cdb38ca248ffe8c7ad5cdcb290b3ae8d4
4
+ data.tar.gz: e51eef767608a111aa1c119ea367ab5bf159cd072f6c4c3015cc588f2e938c46
5
5
  SHA512:
6
- metadata.gz: 22fa12a82821559899257b51557b61304993c50732891577fa40cfbc8efc8a47b8bd29bfcb0b84765ab0d06208d5342427a09f2485b841466aca05f5dcb09e7b
7
- data.tar.gz: 497001f35ecff93d31d44c761dc70fd30bdc95e1d4ab69a317146e2373e9db2f0947dc53d43e69ebf492d5154191d9cc7a719ad93d4997d330739d7672b8f17e
6
+ metadata.gz: bada0281d88dce8ec44033d833c2df8e974cda38e0040bdfc3081f5987607955591588b36f9c59a556f32f3462063798ba5dbcda2635262b606ccf285c96bc42
7
+ data.tar.gz: 47c446ca6abd2eabf63bf332c2918b3f13590f8ad1c4a29bbc888c965613f59effe9d539e27d8d4c9c8b1583c8186118af5bcc9dfe3a7a5f260a7c899c484cf0
data/.dockerignore ADDED
@@ -0,0 +1,2 @@
1
+ .git/
2
+ .git*
data/.gitlab-ci.yml CHANGED
@@ -24,7 +24,7 @@ test:
24
24
  script:
25
25
  - gem install bundler
26
26
  - bundle install
27
- - xvfb-run bundle exec rake
27
+ - bundle exec rake
28
28
 
29
29
  pages:
30
30
  stage: deploy
data/ChangeLog CHANGED
@@ -0,0 +1,3 @@
1
+ Version 0.1.1
2
+ * Enhancement
3
+ * Use Javascript through Selenium to perform link checks
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 /mysuite
6
- WORKDIR /mysuite
7
- COPY . /mysuite/
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
- command = %w[jekyll serve -s test_site]
16
- ENV['test_site_pid'] = Process.spawn(*command, err: %w[logs/test_site.log w]).to_s
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'] = 'localhost:4000'
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
- puts File.join(File.dirname(__FILE__), '..', 'spec')
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
@@ -3,6 +3,9 @@
3
3
  require 'generic_test/version'
4
4
  require 'generic_test/page'
5
5
  require 'generic_test/checker'
6
+ require 'spellcheck'
7
+ require 'watir'
8
+ require 'webdrivers'
6
9
 
7
10
  module GenericTest
8
11
  class Error < StandardError; end
@@ -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
- RestClient.get(href).code
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
@@ -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
- def initialize(url, links)
8
- self.links = links
9
- self.url = url
10
- puts "Found #{links.count} links at #{url}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenericTest
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -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
- sleep 1
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
@@ -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 do
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
@@ -8,6 +8,8 @@
8
8
  </header>
9
9
  <p>
10
10
  Generic test page makes things easy
11
+ All tests in this page work
11
12
  </p>
13
+ <a href="index.html">Index page</a>
12
14
  </body>
13
15
  </html>
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.0
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-12 00:00:00.000000000 Z
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
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: rspec
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
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bash
2
- xvfb-run generic_test page https://samuel-garratt.gitlab.io/generic_test