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

Pr 4: find_xml_file #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Pr 4: find_xml_file #5

wants to merge 2 commits into from

Conversation

CheezItMan
Copy link

No description provided.

Comment on lines +6 to +12

files.each do |filename|
if filename.match "\.xml$"
xml_file = filename
break
end
end

Choose a reason for hiding this comment

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

This will only return the first xml file in the provided folder. Consider the case that multiple .xml files might exist.

Comment on lines +7 to +12
files.each do |filename|
if filename.match "\.xml$"
xml_file = filename
break
end
end

Choose a reason for hiding this comment

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

Suggested change
files.each do |filename|
if filename.match "\.xml$"
xml_file = filename
break
end
end
xml_file = files.find{|filename| filename.match "\.xml$"}

Choose a reason for hiding this comment

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

Consider using the .find method to make the code more elegant and readable.

Copy link

@Schmarj3 Schmarj3 left a comment

Choose a reason for hiding this comment

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

Good stuff! Curious to hear what you think about the suggestions~!


def find_xml_file(folder)
files = Dir.entries(folder)

Choose a reason for hiding this comment

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

I think this code works. I wonder if there is a way to use .include in place of a .each loop unless there is a reason for choosing to use an .each loop? If so, would love to hear why for future reference!


describe "find_xml_file" do
it "should return nil if there are no xml files" do
expect(find_xml_file('.')).must_be_nil

Choose a reason for hiding this comment

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

Maybe we can add another test case or change this to a directory without an xml file.

Comment on lines +3 to +7
Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList['test/*_test.rb']
end

Choose a reason for hiding this comment

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

Good use of the .new method 👍🏼

Comment on lines +7 to +11
files.each do |filename|
if filename.match "\.xml$"
xml_file = filename
break
end

Choose a reason for hiding this comment

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

Consider using an if else block in the place of break

Copy link

@SoCodeDo SoCodeDo left a comment

Choose a reason for hiding this comment

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

Overall looks good, suggested some minor changes.

@@ -0,0 +1,10 @@
require 'rake/testtask'

Rake::TestTask.new do |t|

Choose a reason for hiding this comment

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

Use a more descriptive name than 't' to help with clarity

require 'minitest/reporters'
require 'minitest/skip_dsl'
require 'awesome_print'
# Add simplecov

Choose a reason for hiding this comment

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

it looks like you forgot to add require 'simplecov' to this test_helper.rb

Comment on lines +3 to +5
describe "find_xml_file" do
it "should return nil if there are no xml files" do
expect(find_xml_file('.')).must_be_nil

Choose a reason for hiding this comment

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

Consider adding a couple more test cases

def find_xml_file(folder)
files = Dir.entries(folder)

xml_file = nil

Choose a reason for hiding this comment

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

Is there a chance there might be more than 1 .xml file in the directory being searched? if so turning nil into an array might be helpful.

expect(find_xml_file('.')).must_be_nil
end

it "should return an xml file if it's in the folder" do

Choose a reason for hiding this comment

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

If the above nil does become an array, don't forget to adjust test accordingly. :-)

Comment on lines +3 to +11
describe "find_xml_file" do
it "should return nil if there are no xml files" do
expect(find_xml_file('.')).must_be_nil
end

it "should return an xml file if it's in the folder" do
expect(find_xml_file('./test/test_data')).must_equal "example.xml"
end
end

Choose a reason for hiding this comment

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

Consider: adding a test for multiple XML files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants