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

Exclusive assert for files? #11

Open
nessthehero opened this issue Mar 4, 2016 · 7 comments
Open

Exclusive assert for files? #11

nessthehero opened this issue Mar 4, 2016 · 7 comments
Labels

Comments

@nessthehero
Copy link

Is there a way to do an assert.file() but check if only the files I specify are in the directory?

As in, if any files I don't mention exist, fail the test.

@SBoudrias
Copy link
Member

That could be a new assertion method.

What's the use case?

@nessthehero
Copy link
Author

My team uses a yeoman generator that pulls in files from other repositories, as a way of managing those parts of the project separately. E.g. we can update the default sass for the generator without updating the root code of the actual generator.

Every time I make changes, I need to update the tests that make sure all the files were put in the right place. However, I am human, so sometimes I forget to add new files to the asserts. So the tests pass but I'm not actually accounting for the files.

It's weird now that I'm thinking about it, but I think it could be useful for other purposes, like detecting unwanted files or file-copy mistakes.

@eddiemonge
Copy link
Member

This could be possible with the already existing api if glob was used instead of path-exists

@nessthehero
Copy link
Author

@eddiemonge sorry for the "from the grave" revival of this thread, but I just wanted to be sure of what I'm gathering from your response. Are you saying that my use-case is already possible using existing functions, or are you just remarking that it would be possible to implement?

@eddiemonge
Copy link
Member

I was remarking on the implementation. At the time (probably currently as well), file checks were done using path-exists. If glob was swapped in instead, then you could use glob's matching and negating features

@eddiemonge
Copy link
Member

Forget what I said about glob, you would have to know what you don't want to see, at which point you would probably use noFile.

What would you expect the API for this to look like? I am thinking it might be too complex.

assert.onlyFilesInDirectory([files], dir);

@deimyts
Copy link

deimyts commented Feb 23, 2017

I'd like to chime in on this and say that I have a similar use-case to @nessthehero.

I'm also pulling in files from different repositories.
He mentioned adding new files, but forgetting to test for them, which I've experienced.

I'd also add that some of the repos that my generator pulls in have files that need to be included elsewhere, but not in the generator. If there are more than a few of these, using assert.noFile() can be unwieldy, especially if the names of those files change.

I think it'd be much simpler to maintain if I could stick to specifying only the positive assertions, and have the tests fail if additional, unwanted files are present.

As far as the API, I think it would make more sense to have the directory come first, and the files array come second: assert.onlyFilesInDir(dir, [files]), since that would reflect the order of the actual file paths.

Edit:
The assertion name could also possibly be shortened from onlyFilesInDirectory to just only or onlyFiles.

assert.onlyFiles('path/to/dir', [
  'file1.txt',
  'file3.txt',
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants