rspec_file_chef 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6fadfe59eea88acb49e79650348219fccdb3b51f0c9fad2c6c7c5976fb464d4
4
+ data.tar.gz: da9b088cbfcb54ea7dc5a8fcbf53dfde050f21afa128ea261c485034d73626d9
5
+ SHA512:
6
+ metadata.gz: 12b886de9637042d5bd763a6bf7a7e9137bc7a89cc3850da53ff7e547049996b2c66d7dc4fff2259dffe8cf26a68db35458552e0fa57371fc7c8114de7c4c8b9
7
+ data.tar.gz: '08b3cc949beb54c750f5b5d3313ae10ea2bdee5e056fc9223514126b47e0a81b3c05d9cb99cd639b2fdf882c210a7a9d27e5c66187ae424984e37c91238819d1'
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.rspec_status
2
+ /pkg
3
+ /coverage/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at admin@bestweb.com.ua. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'dry-configurable'
6
+
7
+ group :test do
8
+ gem 'rspec'
9
+ gem 'simplecov', '~> 0.13.0'
10
+ gem 'codeclimate-test-reporter'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ codeclimate-test-reporter (1.0.8)
5
+ simplecov (<= 0.13)
6
+ concurrent-ruby (1.0.5)
7
+ diff-lcs (1.3)
8
+ docile (1.1.5)
9
+ dry-configurable (0.7.0)
10
+ concurrent-ruby (~> 1.0)
11
+ json (2.1.0)
12
+ rspec (3.7.0)
13
+ rspec-core (~> 3.7.0)
14
+ rspec-expectations (~> 3.7.0)
15
+ rspec-mocks (~> 3.7.0)
16
+ rspec-core (3.7.1)
17
+ rspec-support (~> 3.7.0)
18
+ rspec-expectations (3.7.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.7.0)
21
+ rspec-mocks (3.7.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-support (3.7.1)
25
+ simplecov (0.13.0)
26
+ docile (~> 1.1.0)
27
+ json (>= 1.8, < 3)
28
+ simplecov-html (~> 0.10.0)
29
+ simplecov-html (0.10.2)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ codeclimate-test-reporter
36
+ dry-configurable
37
+ rspec
38
+ simplecov (~> 0.13.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Vladislav Trotsenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,253 @@
1
+ # RSpec File Chef
2
+ <a href="https://codeclimate.com/github/bestwebua/rspec_file_chef/maintainability"><img src="https://api.codeclimate.com/v1/badges/4d21c733276304e2e8e1/maintainability" /></a> <a href="https://codeclimate.com/github/bestwebua/rspec_file_chef/test_coverage"><img src="https://api.codeclimate.com/v1/badges/4d21c733276304e2e8e1/test_coverage" /></a> [![Gem Version](https://badge.fury.io/rb/rspec_file_chef.svg)](https://badge.fury.io/rb/rspec_file_chef)
3
+
4
+ The 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.
5
+
6
+ ## Features
7
+
8
+ - Tracking of necessary files
9
+ - Supporting of virtual files
10
+ - Saving/restoring current state of tracking files
11
+ - Supporting of tracking files test examples
12
+ - Ability to use custom location for test examples and temp directory
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'rspec_file_chef'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install rspec_file_chef
29
+
30
+ ## Class configuration
31
+ Before creating class instance you should configurate your FileChef class, otherwise you get RuntimeError.
32
+
33
+ If you don't want to use custom paths configurate your rspec_path only:
34
+ ```ruby
35
+ RspecFileChef::FileChef.configure do |config|
36
+ config.rspec_path = 'your_absolute_path_to_project_rspec_dir'
37
+ end
38
+ ```
39
+
40
+ Configurate as below if you want to use your custom paths only:
41
+ ```ruby
42
+ RspecFileChef::FileChef.configure do |config|
43
+ config.custom_tmp_dir = 'your_absolute_path_to_existing_tmp_dir'
44
+ config.custom_test_dir = 'your_absolute_path_to_existing_test_dir'
45
+ end
46
+ ```
47
+
48
+ ## Public class methods
49
+
50
+ ### .new
51
+
52
+ ```ruby
53
+ RspecFileChef::FileChef.new(file)
54
+ ```
55
+
56
+ Create 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:
57
+
58
+ ```ruby
59
+ file1, file2, file3 = '/path/somefile1', '/path/path/somefile2', '/path/path/path/somefile3'
60
+ ```
61
+
62
+ Also you can pass more than one argument, for instance:
63
+ ```ruby
64
+ file_chef_instance = RspecFileChef::FileChef.new(file1, file2 file3, file_n)
65
+ ```
66
+
67
+
68
+ ## Public instance methods
69
+
70
+ ### #make
71
+
72
+ ```ruby
73
+ file_chef_instance.make
74
+ ```
75
+
76
+ This method prepares your rspec environment files under curry sauce. So what happens when this method run? Your personal FileChef:
77
+
78
+ 1. Creates a path_table. It consists all necessary info about your tracked files.
79
+ 2. Moves your not virtual tracked files to temp dir.
80
+ 3. Creates non existent dirs if you have used virtual files.
81
+ 4. Copies your test examples from test dir to current environment.
82
+
83
+ ### #clear
84
+
85
+ ```ruby
86
+ file_chef_instance.clear
87
+ ```
88
+
89
+ This method is washing dishes in your project folder and restores previous state of tracked files. What happens here?
90
+ 1. Erases test files.
91
+ 2. Restores tracking files.
92
+ 3. Deletes non existent dirs if they were created for virtual files.
93
+
94
+ ### Instance getters
95
+ ---
96
+ ### #tracking_files
97
+
98
+ ```ruby
99
+ file_chef_instance.tracking_files
100
+ ```
101
+
102
+ Returns list of your tracked files in a default order:
103
+
104
+ ```ruby
105
+ # => ['/path/somefile1', '/path/path/somefile2', '/path/path/path/somefile3']
106
+ ```
107
+
108
+
109
+ ### #rspec_path
110
+
111
+ ```ruby
112
+ file_chef_instance.rspec_path
113
+ ```
114
+
115
+ Returns your project spec absolute path:
116
+ ```ruby
117
+ # => '/absolute_path_to_your_project/spec'
118
+ ```
119
+
120
+
121
+ ### #tmp_dir
122
+
123
+ ```ruby
124
+ file_chef_instance.tmp_dir
125
+ ```
126
+
127
+ Returns your project tmp_dir absolute path. When default paths config using:
128
+ ```ruby
129
+ # => '/absolute_path_to_your_project/spec/support/helpers/file_chef/temp_data'
130
+ ```
131
+
132
+ When custom paths config using:
133
+ ```ruby
134
+ # => '/your_absolute_custom_path/your_custom_temp_data_dir'
135
+ ```
136
+
137
+
138
+ ### #test_dir
139
+
140
+ ```ruby
141
+ file_chef_instance.test_dir
142
+ ```
143
+
144
+ Returns your project test_dir absolute path. When default paths config using:
145
+ ```ruby
146
+ # => '/absolute_path_to_your_project/spec/support/helpers/file_chef/test_data'
147
+ ```
148
+
149
+ When custom paths config using:
150
+ ```ruby
151
+ # => '/your_absolute_custom_path/your_custom_test_data_dir'
152
+ ```
153
+
154
+ Put into this dir your files if you want gem to use it as test data examples during your rspec tests run.
155
+
156
+ > 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.
157
+
158
+ ### #test_files
159
+
160
+ ```ruby
161
+ file_chef_instance.test_files
162
+ ```
163
+
164
+ Returns 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**.
165
+
166
+ ```ruby
167
+ # => ['/your_test_dir_absolute_path/somefile1',
168
+ # => '/your_test_dir_absolute_path/somefile2',
169
+ # => '/your_test_dir_absolute_path/somefile3']
170
+ ```
171
+
172
+ ### #path_table
173
+
174
+ ```ruby
175
+ file_chef_instance.path_table
176
+ ```
177
+
178
+ Returns 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**.
179
+
180
+ ```ruby
181
+ # => {'somefile1' => [absolute_file_path, absolute_parent_dir_path, file_exist?, level_depth_of_existing_dir_path]}
182
+ ```
183
+
184
+ ## Examples of using
185
+ What are real and virtual files? Real 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. For 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.
186
+
187
+ **1. Using default gem paths**
188
+
189
+ ```ruby
190
+ # your_project/spec/some_test_class_spec.rb
191
+ require 'rspec_file_chef'
192
+
193
+ RSpec.describe SomeTestClass do
194
+ before(:context) do
195
+ RspecFileChef::FileChef.configure do |config|
196
+ config.rspec_path = File.expand_path(__dir__)
197
+ end
198
+
199
+ file = '/path/somefile1'
200
+
201
+ @env = RspecFileChef::FileChef.new(file)
202
+ @env.make
203
+ end
204
+
205
+ after(:context) do
206
+ @env.clear
207
+ end
208
+ end
209
+ ```
210
+
211
+ **2. Using your custom paths**
212
+
213
+ ```ruby
214
+ # your_project/spec/some_test_class_spec.rb
215
+ require 'rspec_file_chef'
216
+
217
+ RSpec.describe SomeTestClass do
218
+ before(:context) do
219
+ RspecFileChef::FileChef.configure do |config|
220
+ config.custom_tmp_dir = 'your_absolute_path_to_existing_tmp_dir'
221
+ config.custom_test_dir = 'your_absolute_path_to_existing_test_dir'
222
+ end
223
+
224
+ file1, file2, file3 = '/path/somefile1', /path/path/somefile2', '/path/path/path/somefile3'
225
+
226
+ @env = RspecFileChef::FileChef.new(file1, file2, file3)
227
+ @env.make
228
+ end
229
+
230
+ after(:context) do
231
+ @env.clear
232
+ end
233
+ end
234
+ ```
235
+
236
+ **3. Common configuration for all tests**
237
+
238
+ ```ruby
239
+ # your_project/spec/spec_helper.rb
240
+ require 'rspec_file_chef'
241
+
242
+ RspecFileChef::FileChef.configure do |config|
243
+ config.rspec_path = File.expand_path(__dir__)
244
+ end
245
+ ```
246
+
247
+ ## Contributing
248
+
249
+ Bug 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.
250
+
251
+ ## License
252
+
253
+ The RSpec File Environment control application is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rspec_file_chef'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,76 @@
1
+ module RspecFileChef
2
+ module DirInitializer
3
+ HELPER_PATH = 'support/helpers/file_chef'.freeze
4
+
5
+ attr_reader :tmp_dir, :test_dir, :rspec_path
6
+
7
+ private
8
+
9
+ def rspec_pattern
10
+ %r{\A.+?(?=\/spec(\/|\z))}
11
+ end
12
+
13
+ def default_rspec_path
14
+ self.class.config.rspec_path
15
+ end
16
+
17
+ def custom_tmp_dir
18
+ self.class.config.custom_tmp_dir
19
+ end
20
+
21
+ def custom_test_dir
22
+ self.class.config.custom_test_dir
23
+ end
24
+
25
+ def set_rspec_path
26
+ return unless default_rspec_path
27
+ path = default_rspec_path[/#{rspec_pattern}/]
28
+ raise Error::RSPEC_PATH unless path
29
+ @rspec_path = "#{path}/spec"
30
+ end
31
+
32
+ def custom_paths
33
+ [custom_tmp_dir, custom_test_dir]
34
+ end
35
+
36
+ def any_custom_path(&block)
37
+ custom_paths.any?(&block)
38
+ end
39
+
40
+ def not_exist?
41
+ lambda { |path| !Dir.exist?(path) }
42
+ end
43
+
44
+ def check_config
45
+ raise Error::CONFIG if any_custom_path(&:nil?)
46
+ true
47
+ end
48
+
49
+ def custom_paths_needed?
50
+ return false if rspec_path
51
+ check_config
52
+ end
53
+
54
+ def check_custom_paths
55
+ raise Error::CUSTOM_PATHS if any_custom_path(&not_exist?)
56
+ end
57
+
58
+ def create_helper_dir
59
+ %w[temp_data test_data].map do |path|
60
+ path = "#{rspec_path}/#{HELPER_PATH}/#{path}"
61
+ FileUtils.mkdir_p(path)
62
+ path
63
+ end
64
+ end
65
+
66
+ def set_dir_paths
67
+ @tmp_dir, @test_dir =
68
+ if custom_paths_needed?
69
+ check_custom_paths
70
+ custom_paths
71
+ else
72
+ create_helper_dir
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ module RspecFileChef
2
+ module Error
3
+ RSPEC_PATH = 'Wrong rspec path.'.freeze
4
+ CONFIG = 'Config error. You should specify custom tmp_dir and test_dir params.'.freeze
5
+ CUSTOM_PATHS = 'All custom paths should exist.'.freeze
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module RspecFileChef
2
+ class FileChef
3
+ include DirInitializer
4
+ include StateKeeper
5
+ extend Dry::Configurable
6
+
7
+ setting :rspec_path
8
+ setting :custom_tmp_dir
9
+ setting :custom_test_dir
10
+
11
+ def initialize(*tracking_files)
12
+ @tracking_files = tracking_files
13
+ @path_table = {}
14
+ check_tracking_files
15
+ set_rspec_path
16
+ set_dir_paths
17
+ end
18
+
19
+ def make
20
+ create_path_table
21
+ move_to_tmp_dir
22
+ create_nonexistent_dirs
23
+ copy_from_test_dir
24
+ end
25
+
26
+ def clear
27
+ delete_test_files
28
+ restore_tracking_files
29
+ delete_nonexistent_dirs
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,90 @@
1
+ module RspecFileChef
2
+ module StateKeeper
3
+ attr_reader :tracking_files, :path_table
4
+
5
+ def test_files
6
+ path_table.map do |file_name, _|
7
+ "#{test_dir}/#{file_name}"
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def file_pattern
14
+ %r{\A(.+)\/([^\/]+)\z}
15
+ end
16
+
17
+ def tracking_files_not_uniq?
18
+ tracking_files != tracking_files&.uniq
19
+ end
20
+
21
+ def check_tracking_files
22
+ raise 'Tracking files not unique!' if tracking_files_not_uniq?
23
+ end
24
+
25
+ def discover_path_depth(dir_path)
26
+ raise 'Wrong path!' unless dir_path[/\A\//]
27
+ paths = dir_path[1..-1].split('/').map { |item| "/#{item}" }
28
+ paths.each_index.map { |index| paths[0..index].join }.reverse
29
+ end
30
+
31
+ def existing_level_depth(dir_path)
32
+ discover_path_depth(dir_path).index { |path| Dir.exist?(path) }
33
+ end
34
+
35
+ def create_path_table
36
+ tracking_files.each do |file|
37
+ parent_dir = file[/#{file_pattern}/,1]
38
+ status = File.exist?(parent_dir)
39
+ level_depth = existing_level_depth(parent_dir)
40
+ path_table[file[/#{file_pattern}/,2]] = [file, parent_dir, status, level_depth]
41
+ end
42
+ end
43
+
44
+ def move_to_tmp_dir
45
+ path_table.each do |_, file|
46
+ FileUtils.mv(file[0], tmp_dir, force: true)
47
+ end
48
+ end
49
+
50
+ def create_nonexistent_dirs
51
+ path_table.each do |_, file|
52
+ file_dir, dir_exists = file[1..-1]
53
+ FileUtils.mkdir_p(file_dir) unless dir_exists
54
+ end
55
+ end
56
+
57
+ def same_file_path(file)
58
+ file_key = path_table[file[/#{file_pattern}/,2]]
59
+ return file_key unless file_key
60
+ file_key[1]
61
+ end
62
+
63
+ def copy_from_test_dir
64
+ Dir.glob("#{test_dir}/*").each do |file|
65
+ FileUtils.cp(file, same_file_path(file)) if same_file_path(file)
66
+ end
67
+ end
68
+
69
+ def delete_test_files
70
+ path_table.each do |_, file|
71
+ FileUtils.rm(file[0], force: true)
72
+ end
73
+ end
74
+
75
+ def restore_tracking_files
76
+ Dir.glob("#{tmp_dir}/*").each do |file|
77
+ FileUtils.mv(file, same_file_path(file), force: true)
78
+ end
79
+ end
80
+
81
+ def delete_nonexistent_dirs
82
+ path_table.each do |_, file|
83
+ parent_dir, dir_exists, level_depth = file[1..-1]
84
+ level_depth-=1 unless level_depth.zero?
85
+ candidate_to_erase = discover_path_depth(parent_dir)[level_depth]
86
+ FileUtils.rm_r(candidate_to_erase) unless dir_exists
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module RspecFileChef
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'dry-configurable'
2
+ require_relative 'rspec_file_chef/version'
3
+ require_relative 'rspec_file_chef/error'
4
+ require_relative 'rspec_file_chef/dir_initializer'
5
+ require_relative 'rspec_file_chef/state_keeper'
6
+ require_relative 'rspec_file_chef/file_chef'
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rspec_file_chef/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rspec_file_chef'
7
+ spec.version = RspecFileChef::VERSION
8
+ spec.authors = ['Vladislav Trotsenko']
9
+ spec.email = ['admin@bestweb.com.ua']
10
+
11
+ spec.summary = %q{RspecFileChef}
12
+ spec.description = %q{RSpec File Environment control. Keeper of previous state of tracking files and temporary test files cleaner.}
13
+ spec.homepage = 'https://github.com/bestwebua/rspec_file_chef'
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = '>= 2.5.0'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'dry-configurable'
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_file_chef
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladislav Trotsenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dry-configurable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: RSpec File Environment control. Keeper of previous state of tracking
70
+ files and temporary test files cleaner.
71
+ email:
72
+ - admin@bestweb.com.ua
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-version"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/rspec_file_chef.rb
89
+ - lib/rspec_file_chef/dir_initializer.rb
90
+ - lib/rspec_file_chef/error.rb
91
+ - lib/rspec_file_chef/file_chef.rb
92
+ - lib/rspec_file_chef/state_keeper.rb
93
+ - lib/rspec_file_chef/version.rb
94
+ - rspec_file_env.gemspec
95
+ homepage: https://github.com/bestwebua/rspec_file_chef
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.5.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: RspecFileChef
119
+ test_files: []