What is a right way to deal with tests, temporary files and version control - ruby

I use Ruby for writing a code, test it with Cucumber and Rspec and control versions with Git. But here are some unclear things for me. E.g. temporary files, created by tests. I don't want to track their changes with every commit.
So, what way I should use for that:
Locate temporary files inside project folder and use some Git tricks for ignoring changes. gitignore is not useful, because I need some files to be in the place, when tests are started.
Locate temporary files in the /tmp. It gives some unclear for test environment, though.
Any other ways deal with that?

The files required when the tests start should be in source control. Ideally you want temp files created by tests to be in one directory so you can ignore the whole directory. If that's not possible then add each file to the .gitignore file. Really, outside of test results, your specs should clean up after themselves, which should include deleting temp files created during testing.

gitignore is not useful,...
gitignore should be useful here:
either you can limit those temporary files to a dedicated folder within the repo, and you can ignore that all folder;
or you can identify those temporary files by their extension or naming convention, and you can ignore them by a name pattern.

Ruby has facilities for creating temp files and directories and cleaning them up for you, use that. It will pick the correct location for temp files for the current environment, probably well outside your repository, and you never have to worry about them again. While the rule of thumb for tests is to not write files outside your source directory, using a global temp directory is acceptable and reliable.
Otherwise, create a temp directory in your project (possibly inside your test directory) and put all your temp files there. Set .gitignore to ignore that directory. This has the slight advantage of keeping your test artifacts entirely inside your source directory, and you can find them easier for debugging purposes. You should still use Ruby's Tempfile class to manage them, just tell it to use your temp directory, to handle cleanup and to ensure your temp names are unique to allow parallel testing.
I would recommend just using whatever Tempfile.new spits out. Remembering to set the special test temp directory is one more moving part you don't need.

Related

How can I mirror deleted duplicates from a source into a destination?

Here's the scenario: We have a computer running Windows 10 which has a directory that's backed up nightly. The backups are done with a batch file utilizing Robocopy and scheduled via Windows. The parameters are as such that the backup will always add any new files or existing file edits into the destination, but it will never delete files from the destination that have been deleted in the source. It essentially archives all files which are in the source directory at the end of each day.
Here's the tricky part. The source directory is very large, and occasionally someone finds a duplicate file (or several duplicates of a file) in it. When that happens, we need to delete all but one copy of the file, and then we need to access the backup directory manually, locate the file there, and do the same. This is tedious and time-consuming as it's not rare for someone to notice an entire subdirectory full of files that exist 5+ times each.
What we're looking for is a way to scan the source directory and all subdirectories inside for duplicate files and remove all but one copy of them, and then a way to reflect that into the destination. I've assumed that we will not be able to use Robocopy to reflect the changes in the destination due to the nature of the backup script it's running, but we do have the ability to run any third-party software on the destination directory as well, essentially running an action in both directories to clean each of them of duplicate files.
On that note, I'm not against using third-party tools to make this cleaner or more efficient, I'm just not aware of any.
There is one way to solve this problem I was also suffering from this problem. but I found that how to use "BATCH" file
There are mainly 2 command
X_COPY
ROBO_COPY
According to your need here, (1)x_copy will be helpfull
xcopywill backup your specific file or folder even if you changed some megabytes data, it will copy the new data and will not be replaced on previous data it will make new copy.
HOW TO DO
Open NotePad and type
xcopy "source file" "destination" /y/e/d/c/f/h/i/z/j
And then save your notepad as ".bat" file
for more requirement use below url
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy

Move directory and inherit permissions from target folder (as Copy would do)

That's what I want to achieve for my VCL application:
I extract a ZIP file to a directory in %TEMP%. If everything was okay, I move the directory to the target dir.
For the move operation I use JclFileUtils.FileMove (from JCL which resolves to MoveFileEx), because I need a real move operation and I want to overwrite files in the target dir.
This works so far, but the moved files have a per user file permission (inherited from Temp). I want the moved files to inherit permissions from the target folder.
Remarks:
Copy and delete is a workaround, I am aware of. But I want to avoid this (because of file size).
System.IOUtils.TFile.Move does not work for me, because it is implemented by copy and delete (in XE4).
Here a similar problem is described for .NET, but I do not know if an equivalent to GetAccessControl/SetAccessControl exists in Delphi.

What is the maven convention for a directory for test files?

So we have a project that is basically nothing but test files and other projects depend on it to run tests. Problem in the past has been that these items are being unpacked in locations outside of the target directory. That means you end up with modified files and new files, none of which are committed. The files are XML and are used to generate other files. What is the Maven standard location for these files? I'm looking here and I don't see anything that jumps out at me as a conventional location. I can wing it, of course, but I'd prefer to use a standard if it exists:
https://cwiki.apache.org/confluence/display/MAVEN/Maven+Properties+Guide
I'm considering this location:
${project.build.directory}/generated-test-resources/resources
The standard directory for test resoures like xml files is:
/src/test/resources
The way to include these test-only kind of projects is by using test-jar as described here.

Is there a dedicated location in my .git folder where I could put private scripts?

I have some custom filter scripts that I use in my Git repo.
Currently, they are checked in along with my sources which sometimes leads to problems: when I check out a revision older than that where I added the filter scripts to my repo, I get warnings that the filters could not be executed because they cannot be found.
In order to overcome this, I want to put the scripts inside the .git folder so that they are present where I need them but don't make problems when checking out older revisions.
I want to keep them in the repo because the script contents are repo specific, so simply putting them to another location on my machine is not what I'm looking for.
Question is: are there some 'safe' locations inside the .git folder where I could store my scripts?
Safe in the sense that the scripts don't get cleaned up automagically or make problems with further Git versions.
The contents of the .git folder itself aren't very dynamic (what changes rather unpredictably are the refs and the logs, so just stay away from them).
If you take a look at the .git folder of any of your repos, you'll have a pretty good idea what is usually there.
AFAIK, folders in the top level of the .git folder do not usually start with a period, so you could just make a folder .git/.scripts to contain your private script files.
If you want, you can also make that inside the info folder -- that's really up to you and which you find more orderly.
Why not just include the names of the scripts in a .gitignore file? That way, your scripts are not tracked and you can place them anywhere you want in the repo.

a few basic xcode questions

what is copy items into destination group's folder (if needed)
is this a good option? If I dont choose it will it just make a reference to my files?
Also if I have two images with the same name like /images/home.gif, /public/home.gif
but they are in different groups how does the compile know which image to use? is this even possible?
I'll have a crack at this :-)
1 & 2 - Used when adding files to a project. If selected, the file you are adding is copied into the projects directory from wherever it originally was. Note it is copied. If not selected, the project can still use it, it just has a reference to the original source file. Which means that if something happens to the original file, the project will not longer have a copy it can use. Personally for files such as images I copy them into the project so they stay with the project. For other things such as external apis, I don't because I don't want multiple copies everywhere.
3 - If you have two images with the same name you won't be able to copy them in without renaming one. XCode may do this for you, I've never tried. I'd suggest renaming one so you control it's name.
4 - Don't get confused by groups. They are logical groupings of files within XCode and do not refer to the underlying file system. Having said that you can actually assign a directory to a group so if you really wanted to you can match the two. I tend to do it a little. In my projects I generally have a src and test directory. I setup two groups and assign them to refer to these directories. Then when I create a new source code file I can create it in the src or test group and it will be created in the sub-directory instead of the project root directory. Often below src and test I will use other groups, but they do not map to any sub directories. The result is that the root directory of the project is free of source code files and the source code also has source and test code separated.

Resources