Skip to content

Commit eb5f253

Browse files
Merge branch 'spec_update' of https://github.com/antoninmrkvica/website into spec_update
2 parents 3de8edf + 4f1cf5b commit eb5f253

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

spec/pages_spec.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
site = File.join(File.dirname(__FILE__), '..', '_site', '**', '*.html')
55
PAGES = Dir.glob(site).map{ |p| p.gsub(/[^_]+\/_site(.*)/, '\\1') }
66

7+
urls = ['http://localhost:4000', 'http://localhost']
8+
status=''
9+
710
PAGES.each do |p|
811
describe p do
912
it_behaves_like 'Page'
@@ -15,9 +18,23 @@
1518

1619
it 'has only valid internal hyperlinks' do
1720
page.all(:css, 'a').each do |link|
18-
next if link.text == '' || link[:href].match(/(http|\/\/).*/)
19-
page.find(:xpath, link.path).click
20-
expect(page.status_code).to be(200), "expected link '#{link.text}' to work"
21+
next if link.text.nil? || link.text.empty? || link[:href].match(/^http.*/) || link.path.nil? || urls.include?(link[:href])
22+
begin
23+
page.find(:xpath, link.path).click
24+
rescue NoMethodError
25+
require 'irb';binding.irb
26+
end
27+
urls.push link.path
28+
expect(page.status_code).to be(200), "expected link '#{link.text}' to work"
29+
visit p
30+
end
31+
end
32+
33+
it 'has valid external hyperlinks' do
34+
page.all(:css, 'a').each do |link|
35+
next if link.text.nil? || link.text.empty? || !link[:href].match(/^http.*/) || urls.include?(link[:href])
36+
urls.push(link[:href])
37+
expect(url_exists? link[:href], status).to be_truthy, "expected link '#{link.text}' => '#{link[:href]}' to work (Error '#{status}')"
2138
visit p
2239
end
2340
end

0 commit comments

Comments
 (0)