-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Fix and add tests for website Links #73
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
site = File.join(File.dirname(__FILE__), '..', '_site', '**', '*.html') | ||
PAGES = Dir.glob(site).map{ |p| p.gsub(/[^_]+\/_site(.*)/, '\\1') } | ||
|
||
urls = ['http://localhost:4000', 'http://localhost'] | ||
status='' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it possible to do with a number? |
||
|
||
PAGES.each do |p| | ||
describe p do | ||
it_behaves_like 'Page' | ||
|
@@ -15,9 +18,23 @@ | |
|
||
it 'has only valid internal hyperlinks' do | ||
page.all(:css, 'a').each do |link| | ||
next if link.text == '' || link[:href].match(/(http|\/\/).*/) | ||
page.find(:xpath, link.path).click | ||
expect(page.status_code).to be(200), "expected link '#{link.text}' to work" | ||
next if link.text.nil? || link.text.empty? || link[:href].match(/^http.*/) || link.path.nil? || urls.include?(link[:href]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you split this into multiple lines? |
||
begin | ||
page.find(:xpath, link.path).click | ||
rescue NoMethodError | ||
require 'irb';binding.irb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should not be any debug code. |
||
end | ||
urls.push link.path | ||
expect(page.status_code).to be(200), "expected link '#{link.text}' to work" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant now, right? Including the |
||
visit p | ||
end | ||
end | ||
|
||
it 'has valid external hyperlinks' do | ||
page.all(:css, 'a').each do |link| | ||
next if link.text.nil? || link.text.empty? || !link[:href].match(/^http.*/) || urls.include?(link[:href]) | ||
urls.push(link[:href]) | ||
expect(url_exists? link[:href], status).to be_truthy, "expected link '#{link.text}' => '#{link[:href]}' to work (Error '#{status}')" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is probably not a good idea to nest this. Move |
||
visit p | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be made a
Links
object class's instance variable.