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

Move the directory maker into RSpec::Support #74

Merged
merged 1 commit into from
Jun 7, 2014

Conversation

fables-tales
Copy link
Member

Required before rspec/rspec-core#1565 can be merged.

Dir.mkdir(stack)
end
end
end
Copy link
Member

Choose a reason for hiding this comment

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

👍 This looks much cleaner ( ゚ヮ゚) Any reason for the multi-line unless? Just personal taste?

Copy link
Member Author

Choose a reason for hiding this comment

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

@cupakromer will prevent churn in future if anything else needs to happen in that conditional. Makes diffs easier to read IMO.

@fables-tales
Copy link
Member Author

@myronmarston @cupakromer can I get another review pass on this?

describe ".mkdir_p" do
include_context "isolated directory"

let(:dirname) { File.join(%w{tmp a recursive structure}) }
Copy link
Member

Choose a reason for hiding this comment

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

I perfer [ rather than { for these sorts of arrays since [ is the normal array character. With rubocop we can configure and enforce this as well.

@myronmarston
Copy link
Member

One more suggestion: since we want the behavior of this to mirror that of FileUtils.mkdir_p, what do you think about defining the specs as a shared example group that run against both to demonstrate that they have the same behavior? (For example, it's unclear to me if the error raised for failure cases is the same).

expect {
DirectoryMaker.mkdir_p(dirname)
}.not_to raise_error
end
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer this to be a positive expectations:

Dir.mkdir("tmp")
DirectoryMaker.mkdir_p(dirname)
expect(Dir.exist?(dirname)).to be true

This verifies we actually create the remaining directories. Additionally, if an error is raised the spec will still fail.

@myronmarston
Copy link
Member

Would be good to squash this down, too.

it "makes directories recursively" do
DirectoryMaker.mkdir_p(File.expand_path(dirname))
expect(File.exist?(dirname)).to be true
end
Copy link
Member

Choose a reason for hiding this comment

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

Needs a Dir.exist?

@cupakromer
Copy link
Member

One more suggestion: since we want the behavior of this to mirror that of FileUtils.mkdir_p, what do you think about defining the specs as a shared example group that run against both to demonstrate that they have the same behavior?

I like this idea 👍

@fables-tales
Copy link
Member Author

@myronmarston @cupakromer it appears that 1.8.7 has no Dir.exist? method. We could patch one on, or use File.exist? on older rubies. Thoughts?

@myronmarston
Copy link
Member

Let's use File.exist? It's fine. I just thought Dir was more semantic but not worth the overhead of hacking around it.

@cupakromer
Copy link
Member

Just to throw it out there, there is File.directory? in 1.8.7 through 2.1.2. We could create a helper:

def dir_exist?(dirname)
  File.exist?(dirname) && File.directory?(dirname)
end

@JonRowe
Copy link
Member

JonRowe commented Jun 7, 2014

I'd be happy with that solution

@fables-tales
Copy link
Member Author

@myronmarston squash and merge when green?

@cupakromer
Copy link
Member

(。◕‿◕。) LGTM

@fables-tales
Copy link
Member Author

A review comment got suppressed about using %w[] but I fixed it.

@fables-tales
Copy link
Member Author

I'm gonna merge this when travis goes green.

@fables-tales
Copy link
Member Author

(after squashing)

Added so that we don't have to depend on FileUtils and its mkdir_p
implementation anywhere in any of the other RSpec gems.
fables-tales pushed a commit that referenced this pull request Jun 7, 2014
Move the directory maker into RSpec::Support
@fables-tales fables-tales merged commit c313bc2 into master Jun 7, 2014
@fables-tales fables-tales deleted the support-directory-maker branch June 7, 2014 15:10
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.

5 participants