rspec_website_helpers 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f82f1516be5db094e3e8ba76fc96c0005a7cd248
4
+ data.tar.gz: 4ac8ff2be8e31885eacec3150603ca870157a7eb
5
+ SHA512:
6
+ metadata.gz: 22b53d94a6b77d041b510868ab8c983aa01603c69ce99f94c1dd29929b81e2458541ab7330174ac67c453d9d1bf7e689ace722c26eda60cc5a2faf2b7f92af75
7
+ data.tar.gz: 242925b7a7495493000d4d5b0ebb332860b6d4868088bf1a3ae307e12e4f0600826b7fd3c06c433e3c3212d39b8a89f199baba239fd8512235900428852782f3
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec_website_helpers.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # RspecWebsiteHelpers
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rspec_website_helpers`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rspec_website_helpers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rspec_website_helpers
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rspec_website_helpers.
36
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec_website_helpers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ require 'set'
2
+ require 'ostruct'
3
+
4
+ module RspecWebsiteHelpers
5
+ module CollectPages
6
+ end
7
+ end
8
+
9
+ def initialize_path path
10
+ unless @internal_pages[path]
11
+ @internal_pages[path]= OpenStruct.new({fragments: Set.new, referer: Set.new})
12
+ end
13
+ end
14
+
15
+ def collect_targets url, context = url
16
+
17
+ @internal_pages ||= {}
18
+ @external_uris ||= Set.new()
19
+
20
+ visit url
21
+
22
+ current_uri= Addressable::URI.parse(current_url)
23
+
24
+ $logger.info "COLLECTING targets for #{current_uri.path}"
25
+
26
+ initialize_path current_uri.path
27
+
28
+
29
+ local_targets = all("a").map{|a| a[:href]} \
30
+ .map{|href| Addressable::URI.parse(href)} \
31
+ .map{|t| current_uri + t } \
32
+ .map(&:normalize)
33
+
34
+ local_targets.each do |target|
35
+ if (Capybara.app_host == target.site) and (target.path.starts_with? context)
36
+ unless @internal_pages [target.path]
37
+ initialize_path target.path
38
+ collect_targets target, context
39
+ end
40
+ if target.fragment.present? and ! (target.fragment =~ /.+\:.+/)
41
+ @internal_pages[target.path][:fragments].add target.fragment
42
+ end
43
+ @internal_pages[target.path][:referer].add current_uri.path
44
+ else
45
+ @external_uris.add(target)
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+
@@ -0,0 +1,80 @@
1
+ require 'open3'
2
+ require 'addressable/uri'
3
+ require 'faraday'
4
+ require 'rspec/expectations'
5
+
6
+ RSpec::Matchers.define :pass_fragments_check do |properties|
7
+ match do |path|
8
+ @fragment_path = path
9
+ $logger.debug path
10
+ visit path
11
+ if current_path =~ /\/$/ or current_path =~ /html$/
12
+ properties.fragments.each do |fragment|
13
+ unless fragment =~ /^n\d+$/
14
+ @fragment= fragment
15
+ $logger.info "FRAGMENT #{fragment} in #{path}"
16
+ page.all("##{fragment}").count == 1
17
+ end
18
+ end
19
+ else
20
+ true
21
+ end
22
+ end
23
+ failure_message do |path|
24
+ "Expected that fragment '##{@fragment}' would be found on '#{@fragment_path}' but it was not"
25
+ end
26
+ end
27
+
28
+
29
+ RSpec::Matchers.define :pass_spellcheck do |properties|
30
+ match do |path|
31
+ visit path
32
+ $logger.info "SPELLCHECKING visit #{path}"
33
+ if current_path =~ /\/$/ or current_path =~ /html$/
34
+ $logger.info "SPELLCHECKING: #{path}"
35
+ stdin, stdout, stderr, wait_thr= Open3.popen3("hunspell -d #{HUNSPELL_BASE_DICTIONARIES} -p #{HUNSPELL_DICTIONARY_FILE} -l")
36
+ page.evaluate_script('$("code").remove()')
37
+ page.evaluate_script('$("pre").remove()')
38
+ page.evaluate_script('$("sup").remove()')
39
+ @text = page.text
40
+ stdin.print @text
41
+ stdin.close
42
+ @res = stdout.read
43
+ @res.blank?
44
+ else
45
+ true
46
+ end
47
+ end
48
+ failure_message do |path|
49
+ "Expected that #{path} would pass the spellcheck. However, it contains:\n #{@res} \n in its text: \n#{@text}"
50
+ end
51
+ end
52
+
53
+
54
+ RSpec::Matchers.define :pass_existence_check do |properties|
55
+ match do |path|
56
+ $logger.info "PASS_EXISTENCE_CHECK #{path}"
57
+ @uri = Addressable::URI.parse(Capybara.app_host) + Addressable::URI.parse(path)
58
+ @resp= Faraday.new().get(@uri)
59
+ (200..299).include? @resp.status
60
+ end
61
+ failure_message do |path|
62
+ "Expected that getting #{path} would be OK, but it returns #{@resp.status}"
63
+ end
64
+ end
65
+
66
+
67
+ RSpec::Matchers.define :be_an_existing_uri do
68
+ match do |uri|
69
+ unless uri.site =~ /localhost/
70
+ $logger.info "GET check #{uri}"
71
+ @resp= Faraday.new(ssl: {verify: false}).get(uri)
72
+ (200..399).include? @resp.status
73
+ else
74
+ true
75
+ end
76
+ end
77
+ failure_message do |uri|
78
+ "Expected that getting #{uri} would be OK, but it returns #{@resp.status}"
79
+ end
80
+ end
@@ -0,0 +1,42 @@
1
+ shared_context :test_website do |start_path|
2
+
3
+ before :all do
4
+ collect_targets start_path
5
+ $logger.debug internal_pages: @internal_pages
6
+ $logger.debug external_uris: @external_uris
7
+ end
8
+
9
+ it "spellchecking", type: :feature do
10
+ aggregate_failures "for internal pages" do
11
+ @internal_pages.each do |path,properties|
12
+ expect(path).to pass_spellcheck(properties)
13
+ end
14
+ end
15
+ end
16
+
17
+ it "has only existing href targets", type: :feature do
18
+ aggregate_failures "for internal pages" do
19
+ @internal_pages.each do |path,properties|
20
+ expect(path).to pass_existence_check(properties)
21
+ end
22
+ end
23
+ end
24
+
25
+ it "fragment targets exist", type: :feature do
26
+ aggregate_failures "for internal pages" do
27
+ @internal_pages.each do |path,properties|
28
+ expect(path).to pass_fragments_check(properties)
29
+ end
30
+ end
31
+ end
32
+
33
+ it "points only to existing external pages", type: :feature do
34
+ aggregate_failures "external pages" do
35
+ @external_uris.each do |external_uri|
36
+ expect(external_uri).to be_an_existing_uri
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,3 @@
1
+ module RspecWebsiteHelpers
2
+ VERSION = '0.2.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ require "rspec_website_helpers/version"
2
+ require 'active_support/all'
3
+ require "rspec_website_helpers/collect_pages"
4
+ require "rspec_website_helpers/matchers"
5
+ require "rspec_website_helpers/test_website"
6
+
7
+ module RspecWebsiteHelpers
8
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_website_helpers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec_website_helpers"
8
+ spec.version = RspecWebsiteHelpers::VERSION
9
+ spec.authors = ["Thomas Schank"]
10
+ spec.email = ["DrTom@schank.ch"]
11
+
12
+ spec.summary = %q{Helpers for testing websites with rspec.}
13
+ spec.description = %q{Helpers for testing websites with rspec.}
14
+ spec.homepage = "https://github.com/DrTom/rspec_website_helpers.git"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency 'activesupport', '>= 4.0.0', '< 5.0.0'
25
+ spec.add_dependency 'addressable', '>= 2', '< 3'
26
+ spec.add_dependency 'rspec', '>= 3.3', '< 4'
27
+ spec.add_dependency 'faraday'
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_website_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Schank
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 5.0.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 4.0.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 5.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: addressable
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '2'
68
+ - - "<"
69
+ - !ruby/object:Gem::Version
70
+ version: '3'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '2'
78
+ - - "<"
79
+ - !ruby/object:Gem::Version
80
+ version: '3'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '3.3'
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: '4'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '3.3'
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: '4'
101
+ - !ruby/object:Gem::Dependency
102
+ name: faraday
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ type: :runtime
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ description: Helpers for testing websites with rspec.
116
+ email:
117
+ - DrTom@schank.ch
118
+ executables: []
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - ".gitignore"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/rspec_website_helpers.rb
130
+ - lib/rspec_website_helpers/collect_pages.rb
131
+ - lib/rspec_website_helpers/matchers.rb
132
+ - lib/rspec_website_helpers/test_website.rb
133
+ - lib/rspec_website_helpers/version.rb
134
+ - rspec_website_helpers.gemspec
135
+ homepage: https://github.com/DrTom/rspec_website_helpers.git
136
+ licenses: []
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.5.1
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Helpers for testing websites with rspec.
158
+ test_files: []