class_spec_helper 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +13 -2
- data/lib/class_spec_helper/create_classes.rb +22 -2
- data/lib/class_spec_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77fafc1edfe0284bb0071806d91869a50796b28873c6477efaa8479517f85e51
|
4
|
+
data.tar.gz: 150badef8cbdd0a239c4d8dd35ccf0c38412111ad1233a75fb6c4a7029280ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb049001110324fbfc49d65f9289ffd9110c232e7590c5866097b7d50f922d4bb9c7cec447b679d22dbaa482f364244ab5156f957fff78be219ef19c0ead3978
|
7
|
+
data.tar.gz: 23c0f42608ef65be9e75a95234ef7ec4a34881a3f34504cba5350138380d251d858706cd7146a635936763fdbd91577660d2004d926e045e2f5f0db8aeb5d93a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.1.1](https://github.com/craigulliott/class_spec_helper/compare/v1.1.0...v1.1.1) (2023-07-17)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* can now correctly build the new requested class if it is namespaced within already existing classes ([505b8c9](https://github.com/craigulliott/class_spec_helper/commit/505b8c9e07b3a326ac646c90ebb3b537df9d0981))
|
9
|
+
|
10
|
+
## [1.1.0](https://github.com/craigulliott/class_spec_helper/compare/v1.0.0...v1.1.0) (2023-07-17)
|
11
|
+
|
12
|
+
|
13
|
+
### Features
|
14
|
+
|
15
|
+
* manually running the garbage collector to allow for more reliable use of `ObjectSpace` ([87652cb](https://github.com/craigulliott/class_spec_helper/commit/87652cbd601348afbf21f4913483aa558f30d87e))
|
16
|
+
|
3
17
|
## 1.0.0 (2023-07-13)
|
4
18
|
|
5
19
|
|
data/README.md
CHANGED
@@ -51,11 +51,22 @@ require "class_spec_helper"
|
|
51
51
|
|
52
52
|
RSpec.configure do |config|
|
53
53
|
|
54
|
-
# make class_spec_helper conveniently
|
54
|
+
# make class_spec_helper conveniently accessible within your test suite
|
55
55
|
config.add_setting :class_spec_helper
|
56
56
|
config.class_spec_helper = ClassSpecHelper.new
|
57
57
|
|
58
|
-
#
|
58
|
+
# Run the garbage collector before each test. As long as there are no
|
59
|
+
# references in your code to the classes you created during your tests
|
60
|
+
# then this will help ensure that your classes are also completely destroyed.
|
61
|
+
#
|
62
|
+
# If you do not do this, then your deleted classes may still be available
|
63
|
+
# in `ObjectSpace` until the garbage collector runs. Adding this to your
|
64
|
+
# rspec is necessary if your code relies on `ObjectSpace`.
|
65
|
+
config.before(:each) do
|
66
|
+
ObjectSpace.garbage_collect
|
67
|
+
end
|
68
|
+
|
69
|
+
# destroy these dynamically created classes after each test
|
59
70
|
config.after(:each) do
|
60
71
|
config.class_spec_helper.remove_all_dynamically_created_classes
|
61
72
|
end
|
@@ -36,11 +36,21 @@ class ClassSpecHelper
|
|
36
36
|
# is this class nested within a namespace?
|
37
37
|
is_namespaced = module_names.any?
|
38
38
|
if is_namespaced
|
39
|
+
first_name = module_names.shift
|
40
|
+
# keep track of the namespace
|
41
|
+
namespace = "::#{first_name}"
|
42
|
+
# does this exist, and is it a class
|
43
|
+
is_class = Module.const_defined?(namespace) && Module.const_get(namespace).is_a?(Class)
|
39
44
|
# first module is always prepended by a "::" to ensure it is at the top most level
|
40
|
-
eval_code_lines << "module ::#{
|
45
|
+
eval_code_lines << "#{is_class ? "class" : "module"} ::#{first_name}"
|
41
46
|
# each remaining module name is just nested within this top most module
|
42
47
|
module_names.each do |module_name|
|
43
|
-
|
48
|
+
# keep building the namespace we we go
|
49
|
+
namespace = "#{namespace}::#{module_name}"
|
50
|
+
# does this exist, and is it a class
|
51
|
+
is_class = is_class = Module.const_defined?(namespace) && Module.const_get(namespace).is_a?(Class)
|
52
|
+
# add the next line
|
53
|
+
eval_code_lines << "#{is_class ? "class" : "module"} #{module_name}"
|
44
54
|
end
|
45
55
|
end
|
46
56
|
# the class definition
|
@@ -67,6 +77,16 @@ class ClassSpecHelper
|
|
67
77
|
|
68
78
|
# finish building the class
|
69
79
|
klass.class_eval(&block) if block
|
80
|
+
|
81
|
+
# If we are using this in a test suite and the same class names are being used
|
82
|
+
# between each test, then after creation has proven to be a good time to run the
|
83
|
+
# garbage collector manually. It is very likely that all references to the old
|
84
|
+
# class are gone at this point.
|
85
|
+
#
|
86
|
+
# We do this because it is possibe that this is being used within a test suite
|
87
|
+
# for an application which makes use of `ObjectSpace`, and deleted classes will
|
88
|
+
# still be available in `ObjectSpace` until the garbage collector runs.
|
89
|
+
ObjectSpace.garbage_collect
|
70
90
|
end
|
71
91
|
end
|
72
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: class_spec_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Ulliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem to create named classes for use within your specs, and then
|
14
14
|
clear them out automatically between specs.
|