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 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList['test/*_test.rb']
end

task default: :test

15 changes: 15 additions & 0 deletions find_xml_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

Choose a reason for hiding this comment

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

Consider adding a comment to describe the purpose of this function

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

Choose a reason for hiding this comment

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

What is Dir? Please add comment to explain where this comes from

Copy link

Choose a reason for hiding this comment

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

please include to describe what this does


xml_file = nil

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

Choose a reason for hiding this comment

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

Are you only looking for the last xml file? This will replace the xml file each time it finds one

break
Copy link

Choose a reason for hiding this comment

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

use return instead of break

end

Choose a reason for hiding this comment

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

This will iterate through "files", break and return the first match and not all matches, is that your intention?

end

return xml_file
Copy link

Choose a reason for hiding this comment

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

what is xml_file is still nil (i.e., no match) - do you want to return an informative statement in this case?

end
11 changes: 11 additions & 0 deletions test/find_xml_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative 'test_helper'

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

Choose a reason for hiding this comment

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

Looks good

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.

Is "example.xml" the only xml file in your test data folder? Consider clarifying which xml file you are expecting it to find

expect(find_xml_file('./test/test_data')).must_equal "example.xml"
end
end
Empty file added test/test_data/example.xml
Empty file.
13 changes: 13 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'minitest'
require 'minitest/autorun'
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.

include simplecov!

Choose a reason for hiding this comment

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

simplecov doesn't look like it was added


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

# Require_relative your lib files here!

require_relative '../find_xml_file.rb'