Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Remove fileutils #1565

Merged
merged 2 commits into from
Jun 7, 2014
Merged

Remove fileutils #1565

merged 2 commits into from
Jun 7, 2014

Conversation

fables-tales
Copy link
Member

Series of commits removing dependencies on fileutils. I think I got them all. Fixes #1564

@JonRowe
Copy link
Member

JonRowe commented Jun 1, 2014

Seems legit to me

@fables-tales
Copy link
Member Author

This needs the RSpec support PR merging first, but then I think it will work.

@JonRowe
Copy link
Member

JonRowe commented Jun 1, 2014

Restarted the build to find out ;)

@fables-tales
Copy link
Member Author

Ah, emails came in out of order. I see that you've merged it now :)

@cupakromer
Copy link
Member

Maybe this is something that should be moved to rspec-support?

Dir.mkdir(File.join(stack))
rescue Errno::EISDIR
rescue Errno::EEXIST
end
Copy link
Member

Choose a reason for hiding this comment

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

In general we aren't building long paths. However, why not make stack a String:

stack = ""
if stack.empty? && part == ""
  stack = File::SEPARATOR   # This may have issues on Windows??
else
  stack = File.join(stack, part)
end

Then there's no need to keep re-joining the path parts.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 that's much better. Thanks for the tip.

Copy link
Member

Choose a reason for hiding this comment

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

Since in most cases where we have multiple directories to check (ala rspec-rails) most of the path will already exist. If we check for the directory existence first instead of letting the error bubble up, the perf improves ~4x:

# Benchmarking code
require "benchmark"
require "benchmark/ips"
require "tmpdir"
require 'fileutils'

TMPDIR = 'tempdir'
TMPFILE = 'tempfile'

Dir.mktmpdir do |dir|
  FileUtils.chdir dir
  FileUtils.touch TMPFILE
  FileUtils.mkdir TMPDIR
  Benchmark.ips do |r|

    r.report("Dir: check first") do
      Dir.mkdir(TMPDIR) unless File.exist?(TMPDIR)
    end

    r.report("Dir: with rescue") do
      begin
        Dir.mkdir(TMPDIR)
      rescue
      end
    end

    r.report("File: check first") do
      Dir.mkdir(TMPFILE) unless File.exist?(TMPFILE)
    end

    r.report("File: with rescue") do
      begin
        Dir.mkdir(TMPFILE)
      rescue
      end
    end

  end
end
Calculating -------------------------------------
    Dir: check first     24961 i/100ms
    Dir: with rescue      9387 i/100ms
   File: check first     26349 i/100ms
   File: with rescue      9232 i/100ms
-------------------------------------------------
    Dir: check first   498909.9 (±14.2%) i/s -    2446178 in   5.031855s
    Dir: with rescue   110663.3 (±8.5%) i/s -     553833 in   5.045112s
   File: check first   483680.0 (±14.0%) i/s -    2371410 in   5.018733s
   File: with rescue   110862.5 (±10.1%) i/s -     553920 in   5.054816s

I ran this on my 2012 MacBook Air 1.8 GHz i5 with 8GB 1600MHz DDR3 using Ruby 2.1.1.

@fables-tales
Copy link
Member Author

I've moved the directory maker into RSpec Support and added some tests over there, I also applied @cupakromer's suggested improvements on that implementation.

@cupakromer
Copy link
Member

LGTM merge when support is ready.

@fables-tales
Copy link
Member Author

Let's leave it until 3.0.0 is done?

@cupakromer
Copy link
Member

Yeah sure, I don't have a real opinion either way, it should just be an internal refactor and not a change in external behavior.

@JonRowe
Copy link
Member

JonRowe commented Jun 1, 2014

I suspect @myronmarston will side with Sam here and say ship it after 3 ships.

@myronmarston
Copy link
Member

I suspect @myronmarston will side with Sam here and say ship it after 3 ships.

Yep :). Not worth the risk it introduces.

@fables-tales
Copy link
Member Author

Is this still good to merge? Does it need a changelog entry?

@myronmarston
Copy link
Member

Needs a changelog entry and to be squashed, but looks good otherwise.

fables-tales pushed a commit that referenced this pull request Jun 7, 2014
Sam Phippen added 2 commits June 7, 2014 16:45
We now use our own implementation: RSpec::Support::DirectoryMaker
instead which implements mkdir_p for us.
Conflicts:
	Changelog.md
fables-tales pushed a commit that referenced this pull request Jun 7, 2014
@fables-tales fables-tales merged commit bc1c4ab into master Jun 7, 2014
@fables-tales fables-tales deleted the remove-fileutils branch June 7, 2014 21:25
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Conflicts:
	Changelog.md
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop depending on fileutils
4 participants