Skip to content

Pr 4#4

Open
CheezItMan wants to merge 2 commits intomasterfrom
pr-4
Open

Pr 4#4
CheezItMan wants to merge 2 commits intomasterfrom
pr-4

Conversation

@CheezItMan
Copy link
Copy Markdown

This method finds the 1st xml file in the folder.

Copy link
Copy Markdown

@evelynnkaplan evelynnkaplan left a comment

Choose a reason for hiding this comment

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

A few small questions, look good otherwise.

Comment thread find_xml_file.rb
end
end

return xml_file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If xml_file remains nil, is that what we want to return?

Comment thread test/find_xml_test.rb

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

Choose a reason for hiding this comment

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

Could we assign the output of the method call to a variable and then expect that value of that variable to be nil?

Comment thread test/find_xml_test.rb
expect(find_xml_file('.')).must_be_nil
end

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

Choose a reason for hiding this comment

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

In what folder?

Comment thread test/test_helper.rb
require 'minitest'
require 'minitest/autorun'
require 'minitest/reporters'
require 'minitest/skip_dsl'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Are all of these requires needed if we've already required minitest in the first require? As in, is autorun already imported when we require minitest?

Comment thread test/find_xml_test.rb
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
Copy link
Copy Markdown

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 a case in which there is more than one xml file.

Comment thread find_xml_file.rb

xml_file = nil

files.each do |filename|
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm curious how the Dir.entries(folder) works. What order will the each loop evaluate the files in? This is for my own understanding of how this code works.

Copy link
Copy Markdown

@kanderson38 kanderson38 left a comment

Choose a reason for hiding this comment

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

Looks good! One comment for you.

Comment thread test/find_xml_test.rb

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

Choose a reason for hiding this comment

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

Should we pass an actual empty folder in to this test instead of the current directory?

Comment thread find_xml_file.rb
end
end

return xml_file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would consider replacing the break in line 10 with this return xml_file to DRY up the code.

Comment thread test/test_helper.rb

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

# Require_relative your lib files here!
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider removing unused code.

Comment thread find_xml_file.rb
def find_xml_file(folder)
files = Dir.entries(folder)

xml_file = nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If no .xml in files, return will be nil.

Comment thread find_xml_file.rb
xml_file = nil

files.each do |filename|
if filename.match "\.xml$"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dir['*.xml'] offers a convenient way to do this or Dir['**/*.xml'] in case of subdirectories

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.

7 participants