Spwn
Spwn is a testing library for random file production. It basically allows you to quickly throw some files up, test your methods on them, and quickly clean up your filestructure.
Installation
Throw spwn
in your Gemfile:
gem 'spwn'
and bundle
$ bundle
Or install it yourself as:
$ gem install spwn
Usage
Returning something useful
This currently is the source of a major issue. Each time a File object is created a file pointer is used. The user woudl need to manually
f.close
each file. I am currently building a seperate library to create aFile
replacement that doesn't immediately open a file buffer and has a more robust set of useful istance methods.
In almost all the following methods, you will find either a Dir or File object returned to you. Why do this instead of return a path to the file? Easy! You can do cool stuff like this now:
# Look! You can still get the path...
Uber.pwd.path #=> "/home/michael/code"
# ...but you can also iterate through files as well now!
Uber.pwd.each { |item| puts 'item' }
which would produce
.
..
migrateServer
superSecretProject
or with File
...
# return the file size in bytes
Uber.file('Gemfile').size #=> 171
# change file permissions (I believe this needs root permissions)
Uber.file('Gemfile').chmod('0644')
You can also use the returned File or Dir class in that respective class's class methods!
gemfile = Uber.file('Gemfile')
File.executable?(gemfile) #=> false
Spawning Files
Spwn.file #=> <File:file1.html>
Spwn.file #=> <File:file2.md>
Spwn.file( ext: 'md' ) #=> <File:file3.rb>
Spwn.file( 'index.html' ) #=> <File:index.html>
Spwn.file( count: 3 ) #=> [<File:file4.md>,<File:file5.txt>,<File:file6.rb>]
Spwn.dir #=> <Dir:dir1>
Spwn.dir( 'spec' ) #=> <Dir:spec>
#spawn a dir and then cd inside the dir to do stuff
Spwn.dir( 'scripts' ) do
Spwn.dir( 'vendor' )
Spwn.file( 'app.js' )
Dir.pwd() #=> '.../mySite/scripts'
end
removing spawned files
All done testing and need to clean up those files? Just run
Spwn.clean( 'spec/tmp' )
to empty the directory completely.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request