-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: master
Are you sure you want to change the base?
Conversation
|
||
files.each do |filename| | ||
if filename.match "\.xml$" | ||
xml_file = filename | ||
break | ||
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 will only return the first xml file in the provided folder. Consider the case that multiple .xml files might exist.
files.each do |filename| | ||
if filename.match "\.xml$" | ||
xml_file = filename | ||
break | ||
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.
files.each do |filename| | |
if filename.match "\.xml$" | |
xml_file = filename | |
break | |
end | |
end | |
xml_file = files.find{|filename| filename.match "\.xml$"} |
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.
Consider using the .find method to make the code more elegant and readable.
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.
Good stuff! Curious to hear what you think about the suggestions~!
|
||
def find_xml_file(folder) | ||
files = Dir.entries(folder) | ||
|
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.
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 |
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.
Maybe we can add another test case or change this to a directory without an xml file.
Rake::TestTask.new do |t| | ||
t.libs = ["lib"] | ||
t.warning = true | ||
t.test_files = FileList['test/*_test.rb'] | ||
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.
Good use of the .new method 👍🏼
files.each do |filename| | ||
if filename.match "\.xml$" | ||
xml_file = filename | ||
break | ||
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.
Consider using an if else block in the place of break
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.
Overall looks good, suggested some minor changes.
@@ -0,0 +1,10 @@ | |||
require 'rake/testtask' | |||
|
|||
Rake::TestTask.new do |t| |
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.
Use a more descriptive name than 't' to help with clarity
require 'minitest/reporters' | ||
require 'minitest/skip_dsl' | ||
require 'awesome_print' | ||
# Add simplecov |
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 looks like you forgot to add require 'simplecov'
to this test_helper.rb
describe "find_xml_file" do | ||
it "should return nil if there are no xml files" do | ||
expect(find_xml_file('.')).must_be_nil |
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.
Consider adding a couple more test cases
def find_xml_file(folder) | ||
files = Dir.entries(folder) | ||
|
||
xml_file = nil |
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.
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 |
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.
If the above nil does become an array, don't forget to adjust test accordingly. :-)
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 |
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.
Consider: adding a test for multiple XML files.
No description provided.