Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions spec/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Copy link
Contributor

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.

status=''
Copy link
Contributor

Choose a reason for hiding this comment

The 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'
Expand All @@ -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])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you split this into multiple lines?
Maybe add a comment?

begin
page.find(:xpath, link.path).click
rescue NoMethodError
require 'irb';binding.irb
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant now, right? Including the visit method.

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}')"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably not a good idea to nest this. Move url_exists? out of the expect.

visit p
end
end
Expand Down