{"id":15405790,"url":"https://github.com/bestwebua/rspec_file_chef","last_synced_at":"2026-05-02T09:32:36.733Z","repository":{"id":56892862,"uuid":"140683735","full_name":"bestwebua/rspec_file_chef","owner":"bestwebua","description":"Rspec File Chef - File Environment control :floppy_disk:","archived":false,"fork":false,"pushed_at":"2020-03-23T07:41:41.000Z","size":71,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-02T04:25:31.030Z","etag":null,"topics":["rspec","rspec-testing","ruby","ruby-gem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bestwebua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-12T08:21:26.000Z","updated_at":"2020-05-01T17:36:47.000Z","dependencies_parsed_at":"2022-08-21T01:20:50.538Z","dependency_job_id":null,"html_url":"https://github.com/bestwebua/rspec_file_chef","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestwebua%2Frspec_file_chef","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestwebua%2Frspec_file_chef/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestwebua%2Frspec_file_chef/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bestwebua%2Frspec_file_chef/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bestwebua","download_url":"https://codeload.github.com/bestwebua/rspec_file_chef/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245955716,"owners_count":20699963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rspec","rspec-testing","ruby","ruby-gem"],"created_at":"2024-10-01T16:18:35.889Z","updated_at":"2026-05-02T09:32:36.676Z","avatar_url":"https://github.com/bestwebua.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RSpec File Chef\n\u003ca href=\"https://codeclimate.com/github/bestwebua/rspec_file_chef/maintainability\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/4d21c733276304e2e8e1/maintainability\" /\u003e\u003c/a\u003e \u003ca href=\"https://codeclimate.com/github/bestwebua/rspec_file_chef/test_coverage\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/4d21c733276304e2e8e1/test_coverage\" /\u003e\u003c/a\u003e [![Gem Version](https://badge.fury.io/rb/rspec_file_chef.svg)](https://badge.fury.io/rb/rspec_file_chef) [![Build Status](https://travis-ci.org/bestwebua/rspec_file_chef.svg?branch=master)](https://travis-ci.org/bestwebua/rspec_file_chef)\n\nThe main idea of this gem is saving previous state of tracking files after running RSpec. It should be helpful when your project is using it's own local files to record some data or a log. And you don't want RSpec to change it. Or you don't want to get a lot of temporary test files in your project root folder after your tests were complete.\n\n## Features\n\n- Tracking of necessary files\n  - Supporting of virtual files\n  - Saving/restoring current state of tracking files\n- Supporting of tracking files test examples\n- Ability to use custom location for test examples and temp directory\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rspec_file_chef'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rspec_file_chef\n\n## Class configuration\nBefore creating class instance you should configurate your FileChef class, otherwise you get RuntimeError.\n\nIf you don't want to use custom paths configurate your rspec_path only:\n```ruby\nRspecFileChef::FileChef.configure do |config|\n  config.rspec_path = 'your_absolute_path_to_project_rspec_dir'\nend\n```\n\nConfigurate as below if you want to use your custom paths only:\n```ruby\nRspecFileChef::FileChef.configure do |config|\n  config.custom_tmp_dir = 'your_absolute_path_to_existing_tmp_dir'\n  config.custom_test_dir = 'your_absolute_path_to_existing_test_dir'\nend\n```\n\n## Public class methods\n\n### .new\n\n```ruby\nRspecFileChef::FileChef.new(file)\n```\n\nCreate new instance of RspecFileChef::FileChef. Passed argument is your file-list for your tracking files. It should be real or virtual absolute paths represented as a string. **Please note, file-names of tracking files should be unique, otherwise you get RuntimeError**. For instance:\n\n```ruby\nfile1, file2, file3 = '/path/somefile1', '/path/path/somefile2', '/path/path/path/somefile3'\n```\n\nAlso you can pass more than one argument, for instance:\n```ruby\nfile_chef_instance = RspecFileChef::FileChef.new(file1, file2 file3, file_n)\n```\n\n\n## Public instance methods\n\n### #make\n\n```ruby\nfile_chef_instance.make\n```\n\nThis method prepares your rspec environment files under curry sauce. So what happens when this method run? Your personal FileChef:\n\n1. Creates a path_table. It consists all necessary info about your tracked files.\n2. Moves your not virtual tracked files to temp dir.\n3. Creates non existent dirs if you have used virtual files.\n4. Copies your test examples from test dir to current environment.\n\n### #clear\n\n```ruby\nfile_chef_instance.clear\n```\n\nThis method is washing dishes in your project folder and restores previous state of tracked files. What happens here?\n1. Erases test files.\n2. Restores tracking files.\n3. Deletes non existent dirs if they were created for virtual files.\n\n### Instance getters\n---\n### #tracking_files\n\n```ruby\nfile_chef_instance.tracking_files\n```\n\nReturns list of your tracked files in a default order:\n\n```ruby\n# =\u003e ['/path/somefile1', '/path/path/somefile2', '/path/path/path/somefile3']\n```\n\n\n### #rspec_path\n\n```ruby\nfile_chef_instance.rspec_path\n```\n\nReturns your project spec absolute path:\n```ruby\n# =\u003e '/absolute_path_to_your_project/spec'\n```\n\n\n### #tmp_dir\n\n```ruby\nfile_chef_instance.tmp_dir\n```\n\nReturns your project tmp_dir absolute path. When default paths config using:\n```ruby\n# =\u003e '/absolute_path_to_your_project/spec/support/helpers/file_chef/temp_data'\n```\n\nWhen custom paths config using:\n```ruby\n# =\u003e '/your_absolute_custom_path/your_custom_temp_data_dir'\n```\n\n\n### #test_dir\n\n```ruby\nfile_chef_instance.test_dir\n```\n\nReturns your project test_dir absolute path. When default paths config using:\n```ruby\n# =\u003e '/absolute_path_to_your_project/spec/support/helpers/file_chef/test_data'\n```\n\nWhen custom paths config using:\n```ruby\n# =\u003e '/your_absolute_custom_path/your_custom_test_data_dir'\n```\n\nPut into this dir your files if you want gem to use it as test data examples during your rspec tests run.\n\n\u003e Please note, file-names of tracking files should be unique, and have the same names as files that ```.tracking_files``` method returns. For instance, to use this case you should put: ```somefile1```, ```somefile2```, ```somefile3``` into your test folder.\n\n### #test_files\n\n```ruby\nfile_chef_instance.test_files\n```\n\nReturns list of test files absolute paths that existing in your test_dir folder. The returned list is represented as an array, the elements of which are sorted in the order like ```.tracking_files```  **It makes sense to use this method after method ```.make``` was run. Otherwise you will get empty array**.\n\n```ruby\n# =\u003e ['/your_test_dir_absolute_path/somefile1',\n# =\u003e  '/your_test_dir_absolute_path/somefile2',\n# =\u003e  '/your_test_dir_absolute_path/somefile3']\n```\n\n### #path_table\n\n```ruby\nfile_chef_instance.path_table\n```\n\nReturns associative array, where all tracking file-names are represented as keys. As values returns array with next data-pattern: ```[absolute_file_path, absolute_parent_dir_path, file_exist?, level_depth_of_existing_dir_path]```. **It makes sense to use this method after method ```.make``` was run. Otherwise you will get empty hash**.\n\n```ruby\n# =\u003e {'somefile1' =\u003e [absolute_file_path, absolute_parent_dir_path, file_exist?, level_depth_of_existing_dir_path]}\n```\n\n## Examples of using\n\n### Real and virtual files, what does it mean?\n\nReal file is an existing file which state you want to keep during running tests. Virtual file is a file the state of which you want to control, but this file not exist until you run tests.\n\n**1. Using as cleaner**\n\nFor example, you know which file your app logged. Before your tests run your log-file not existen. You need to check is your app write the log during your tests. But you don't wont to see this log after your tests. This is case for using virtual files. Just pass the absolute path for this file/files as argument: ```RspecFileChef::FileChef.new(your_virtual_file)```.\n\n**2. Using as file switcher**\n\nYour project has use some local data files. You need that this file/files has contain a certain data before you run tests. Just pass the absolute path for this file/files as argument: ```RspecFileChef::FileChef.new(your_file)``` and put file/files with same name(s) into your test_dir. Your file can be either real or virtual. FileChef saves the file state if file is real, and uses example from test_dir during your test run. Otherwise FileChef just uses file from test_dir when your tests running.\n\n### FileChef config examples\n\n**1. Using default gem paths**\n\n```ruby\n# your_project/spec/some_test_class_spec.rb\nrequire 'rspec_file_chef'\n\nRSpec.describe SomeTestClass do\n  before(:context) do\n    RspecFileChef::FileChef.configure do |config|\n      config.rspec_path = File.expand_path(__dir__)\n    end\n\n    file = '/path/somefile1'\n\n    @env = RspecFileChef::FileChef.new(file)\n    @env.make\n  end\n\n  after(:context) do\n    @env.clear\n  end\nend\n```\n\n**2. Using your custom paths**\n\n```ruby\n# your_project/spec/some_test_class_spec.rb\nrequire 'rspec_file_chef'\n\nRSpec.describe SomeTestClass do\n  before(:context) do\n    RspecFileChef::FileChef.configure do |config|\n      config.custom_tmp_dir = 'your_absolute_path_to_existing_tmp_dir'\n      config.custom_test_dir = 'your_absolute_path_to_existing_test_dir'\n    end\n\n    file1, file2, file3 = '/path/somefile1', '/path/path/somefile2', '/path/path/path/somefile3'\n\n    @env = RspecFileChef::FileChef.new(file1, file2, file3)\n    @env.make\n  end\n\n  after(:context) do\n    @env.clear\n  end\nend\n```\n\n**3. Common configuration for all tests**\n\n```ruby\n# your_project/spec/spec_helper.rb\nrequire 'rspec_file_chef'\n\nRspecFileChef::FileChef.configure do |config|\n  config.rspec_path = File.expand_path(__dir__)\nend\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/rspec_file_chef. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe RSpec File Environment control application is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestwebua%2Frspec_file_chef","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbestwebua%2Frspec_file_chef","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbestwebua%2Frspec_file_chef/lists"}