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

Conversation

antoninmrkvica
Copy link
Contributor

No description provided.

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.

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.

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?

@@ -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=''
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?

require 'irb';binding.irb
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.


# 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']
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.

links = Links.new(page.all(:css, 'a'),urls)
links.each do |link|
url=link[:href]
if !is_uri? url
Copy link
Contributor

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

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

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).

@pvalena pvalena changed the title add/edit tests: internal & external WIP: Fix and add tests for website Links Jun 7, 2018
@pvalena pvalena self-assigned this Jun 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants