-
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?
WIP: Fix and add tests for website Links #73
Conversation
spec/pages_spec.rb
Outdated
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 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
.
spec/pages_spec.rb
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
There should not be any debug code.
spec/pages_spec.rb
Outdated
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 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?
spec/pages_spec.rb
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible to do with a number?
spec/pages_spec.rb
Outdated
require 'irb';binding.irb | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant now, right? Including the visit
method.
eb5f253
to
00d9e0e
Compare
00d9e0e
to
3c7fafa
Compare
72d5fd2
to
b7fc8bc
Compare
|
||
# Array of all generated pages | ||
site = File.join(File.dirname(__FILE__), '..', '_site', '**', '*.html') | ||
PAGES = Dir.glob(site).map{ |p| p.gsub(/[^_]+\/_site(.*)/, '\\1') } | ||
|
||
urls = ['http://localhost:4000', 'http://localhost'] |
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.
links = Links.new(page.all(:css, 'a'),urls) | ||
links.each do |link| | ||
url=link[:href] | ||
if !is_uri? url |
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.
Please use unless
instead of if !
.
url=link[:href] | ||
if !is_uri? url | ||
page.find(:xpath, link.path).click | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
In be(200)
the usual practice is to replace the magic constant with a literal
constant (IOW use capitalized variable defined in spec_helper
.
links.each do |link| | ||
url=link[:href] | ||
if is_uri? url | ||
result = Links.url_exists? url |
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.
Thinking of it a bit more the method could return two values instead (you're not passing it anyway and using a global variable).
No description provided.