eac_tools 0.24.0 → 0.25.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +27 -27
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +3 -3
  5. data/sub/avm/lib/avm/entries/auto_values/uri_entry.rb +1 -1
  6. data/sub/avm/lib/avm/entries/base/inherited_entry_value.rb +31 -0
  7. data/sub/avm/lib/avm/entries/base/uri_component_entry_value.rb +71 -0
  8. data/sub/avm/lib/avm/entries/base.rb +2 -10
  9. data/sub/avm/lib/avm/entries/entry.rb +10 -1
  10. data/sub/avm/lib/avm/entries/uri_builder.rb +4 -0
  11. data/sub/avm/lib/avm/instances/base/auto_values/filesystem.rb +0 -5
  12. data/sub/avm/lib/avm/instances/base/auto_values/install.rb +20 -15
  13. data/sub/avm/lib/avm/instances/entry_keys.rb +4 -3
  14. data/sub/avm/lib/avm/version.rb +1 -1
  15. data/sub/avm/spec/lib/avm/instances/base_spec.rb +17 -1
  16. data/sub/avm/spec/lib/avm/instances/base_spec_configs_storage.yml +7 -1
  17. data/sub/avm-eac_redmine_base0/avm-eac_redmine_base0.gemspec +2 -2
  18. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/instances/deploy.rb +37 -0
  19. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/runners/base.rb +1 -1
  20. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/version.rb +1 -1
  21. data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/{deploy → instances/deploy}/config/install.sh.template +0 -0
  22. data/sub/avm-eac_redmine_base0/template/avm/eac_redmine_base0/{deploy → instances/deploy}/config/secrets.yml +0 -0
  23. data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +2 -2
  24. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/sources/runners/update_dependencies_requirements.rb +7 -1
  25. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
  26. data/sub/avm-eac_webapp_base0/avm-eac_webapp_base0.gemspec +2 -2
  27. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/deploy/file_unit.rb +1 -1
  28. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/runner/deploy.rb +2 -0
  29. data/sub/avm-eac_webapp_base0/lib/avm/eac_webapp_base0/version.rb +1 -1
  30. data/sub/eac_config/eac_config.gemspec +2 -2
  31. data/sub/eac_config/lib/eac_config/entry.rb +4 -0
  32. data/sub/eac_config/lib/eac_config/entry_path.rb +6 -1
  33. data/sub/eac_config/lib/eac_config/envvars_node.rb +4 -0
  34. data/sub/eac_config/lib/eac_config/node_entry.rb +5 -0
  35. data/sub/eac_config/lib/eac_config/version.rb +1 -1
  36. data/sub/eac_config/lib/eac_config/yaml_file_node.rb +4 -0
  37. data/sub/eac_config/spec/lib/eac_config/envvars_node_spec.rb +11 -0
  38. data/sub/eac_ruby_utils/eac_ruby_utils.gemspec +2 -2
  39. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_accessors.rb +36 -0
  40. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/class_initialize.rb +14 -4
  41. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor/instance_initialize.rb +15 -4
  42. data/sub/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +20 -15
  43. data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_clean_environment.rb +53 -20
  44. data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_replace_objects/replace_instance_method.rb +36 -0
  45. data/sub/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_replace_objects.rb +52 -0
  46. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  47. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +26 -0
  48. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/{ruby_spec.rb → ruby/on_clean_environment_spec.rb} +11 -0
  49. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/ruby/on_replace_objects_spec.rb +67 -0
  50. metadata +28 -22
  51. data/sub/avm-eac_redmine_base0/lib/avm/eac_redmine_base0/deploy.rb +0 -36
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module EacWebappBase0
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'addressable'
16
- s.add_dependency 'eac_ruby_utils', '~> 0.97'
15
+ s.add_dependency 'addressable', '~> 2.8'
16
+ s.add_dependency 'eac_ruby_utils', '~> 0.102'
17
17
 
18
18
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
19
19
  end
@@ -22,6 +22,10 @@ module EacConfig
22
22
  node_entry.if_present(&:secret_value)
23
23
  end
24
24
 
25
+ def to_s
26
+ "#{self.class}[RootNode: #{root_node}, Path: #{path}]"
27
+ end
28
+
25
29
  def value
26
30
  node_entry.if_present(&:value)
27
31
  end
@@ -51,7 +51,12 @@ module EacConfig
51
51
  end
52
52
 
53
53
  def to_s
54
- "#{self.class}[#{parts.join(PART_SEPARATOR)}]"
54
+ "#{self.class}[#{to_string}]"
55
+ end
56
+
57
+ # @return [String]
58
+ def to_string
59
+ parts.join(PART_SEPARATOR)
55
60
  end
56
61
  end
57
62
  end
@@ -21,5 +21,9 @@ module EacConfig
21
21
  def url
22
22
  URI
23
23
  end
24
+
25
+ def to_s
26
+ "#{self.class}[ObjectId: #{object_id}]}"
27
+ end
24
28
  end
25
29
  end
@@ -18,5 +18,10 @@ module EacConfig
18
18
  def secret_value
19
19
  value
20
20
  end
21
+
22
+ # @return [String]
23
+ def to_s
24
+ "#{self.class}[Node: #{node}, Path: #{path}]"
25
+ end
21
26
  end
22
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacConfig
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.1'
5
5
  end
@@ -31,6 +31,10 @@ module EacConfig
31
31
  ::Addressable::URI.parse("file://#{path.expand_path}")
32
32
  end
33
33
 
34
+ def to_s
35
+ "#{self.class}[#{path}]"
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def data_uncached
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_config/envvars_node'
4
+ require 'eac_ruby_utils/ruby'
4
5
 
5
6
  RSpec.describe ::EacConfig::EnvvarsNode do
6
7
  let(:instance) { described_class.new }
@@ -18,6 +19,16 @@ RSpec.describe ::EacConfig::EnvvarsNode do
18
19
  it { expect(entry.value).to eq('AAA') }
19
20
  it { expect(entry.found_node).to eq(instance) }
20
21
  it { expect(entry).to be_found }
22
+
23
+ context 'with a clean ruby environment' do
24
+ let(:entry_value) do
25
+ ::EacRubyUtils::Ruby.on_clean_environment do
26
+ entry.value
27
+ end
28
+ end
29
+
30
+ it { expect(entry_value).to eq('AAA') }
31
+ end
21
32
  end
22
33
 
23
34
  context 'with blank entry' do
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.files = Dir['{lib}/**/*', 'MIT-LICENSE', 'README.rdoc']
17
17
 
18
18
  s.add_dependency 'activesupport', '>= 4', '< 7'
19
- s.add_dependency 'addressable', '~> 2.6'
19
+ s.add_dependency 'addressable', '~> 2.8'
20
20
  s.add_dependency 'bundler'
21
- s.add_dependency 'filesize'
21
+ s.add_dependency 'filesize', '~> 0.2'
22
22
  s.add_dependency 'net-ssh', '~> 4.2'
23
23
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
24
24
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/common_constructor/instance_initialize'
4
+ require 'eac_ruby_utils/common_constructor/super_args'
5
+
6
+ module EacRubyUtils
7
+ class CommonConstructor
8
+ class ClassAccessors
9
+ attr_reader :common_constructor, :klass
10
+
11
+ def initialize(common_constructor, klass)
12
+ @common_constructor = common_constructor
13
+ @klass = klass
14
+ end
15
+
16
+ def args
17
+ common_constructor.all_args
18
+ end
19
+
20
+ def perform
21
+ setup_class_attr_readers
22
+ setup_class_attr_writers
23
+ end
24
+
25
+ def setup_class_attr_readers
26
+ klass.send(:attr_reader, *args)
27
+ klass.send(:public, *args) if args.any?
28
+ end
29
+
30
+ def setup_class_attr_writers
31
+ klass.send(:attr_writer, *args)
32
+ klass.send(:private, *args.map { |a| "#{a}=" }) if args.any?
33
+ end
34
+ end
35
+ end
36
+ end
@@ -13,17 +13,27 @@ module EacRubyUtils
13
13
  @klass = klass
14
14
  end
15
15
 
16
- def run
16
+ def define_initialize_callbacks
17
+ klass.include(::ActiveSupport::Callbacks)
18
+ klass.define_callbacks :initialize
19
+ end
20
+
21
+ def define_initialize_method
17
22
  class_initialize = self
18
- klass.send(:define_method, :initialize) do |*args|
23
+ klass.send(:define_method, :initialize) do |*args, &block|
19
24
  ::EacRubyUtils::CommonConstructor::InstanceInitialize.new(
20
- class_initialize.common_constructor, args, self
21
- ).run
25
+ class_initialize.common_constructor, args, self, block
26
+ ).perform
22
27
  super(*::EacRubyUtils::CommonConstructor::SuperArgs.new(
23
28
  class_initialize, args, self
24
29
  ).result)
25
30
  end
26
31
  end
32
+
33
+ def perform
34
+ define_initialize_callbacks
35
+ define_initialize_method
36
+ end
27
37
  end
28
38
  end
29
39
  end
@@ -3,18 +3,20 @@
3
3
  module EacRubyUtils
4
4
  class CommonConstructor
5
5
  class InstanceInitialize
6
- attr_reader :common_constructor, :args, :object
6
+ attr_reader :common_constructor, :args, :object, :block
7
7
 
8
- def initialize(common_constructor, args, object)
8
+ def initialize(common_constructor, args, object, block)
9
9
  @common_constructor = common_constructor
10
10
  @args = args
11
11
  @object = object
12
+ @block = block
12
13
  end
13
14
 
14
- def run
15
+ def perform
15
16
  validate_args_count
16
17
  object.run_callbacks :initialize do
17
18
  object_attributes_set
19
+ object_block_set
18
20
  object_after_callback
19
21
  end
20
22
  end
@@ -36,12 +38,21 @@ module EacRubyUtils
36
38
  object.instance_eval(&common_constructor.after_set_block)
37
39
  end
38
40
 
41
+ def object_attribute_set(attr_name, attr_value)
42
+ object.send("#{attr_name}=", attr_value)
43
+ end
44
+
39
45
  def object_attributes_set
40
46
  common_constructor.args.each do |arg_name|
41
- object.send("#{arg_name}=", arg_value(arg_name))
47
+ object_attribute_set(arg_name, arg_value(arg_name))
42
48
  end
43
49
  end
44
50
 
51
+ def object_block_set
52
+ block_arg = common_constructor.block_arg
53
+ object_attribute_set(block_arg, block) if block_arg
54
+ end
55
+
45
56
  def validate_args_count
46
57
  return if common_constructor.args_count.include?(args.count)
47
58
 
@@ -2,12 +2,13 @@
2
2
 
3
3
  require 'active_support/callbacks'
4
4
  require 'eac_ruby_utils/arguments_consumer'
5
+ require 'eac_ruby_utils/common_constructor/class_accessors'
5
6
  require 'eac_ruby_utils/common_constructor/class_initialize'
6
7
  require 'ostruct'
7
8
 
8
9
  module EacRubyUtils
9
10
  class CommonConstructor
10
- attr_reader :args, :options, :after_set_block
11
+ attr_reader :all_args, :options, :after_set_block
11
12
 
12
13
  class << self
13
14
  def parse_args_options(args)
@@ -37,11 +38,15 @@ module EacRubyUtils
37
38
 
38
39
  def initialize(*args, &after_set_block)
39
40
  args_processed = self.class.parse_args_options(args)
40
- @args = args_processed.args
41
+ @all_args = args_processed.args
41
42
  @options = args_processed.options
42
43
  @after_set_block = after_set_block
43
44
  end
44
45
 
46
+ def args
47
+ block_arg? ? all_args[0..-2] : all_args
48
+ end
49
+
45
50
  def args_count
46
51
  (args_count_min..args_count_max)
47
52
  end
@@ -54,32 +59,32 @@ module EacRubyUtils
54
59
  args.count
55
60
  end
56
61
 
62
+ def block_arg
63
+ block_arg? ? all_args.last : nil
64
+ end
65
+
66
+ def block_arg?
67
+ options[:block_arg] || false
68
+ end
69
+
57
70
  def default_values
58
71
  options[:default] || []
59
72
  end
60
73
 
61
74
  def setup_class(klass)
62
- setup_class_attr_readers(klass)
63
- setup_class_attr_writers(klass)
75
+ setup_class_accessors(klass)
76
+
64
77
  setup_class_initialize(klass)
65
78
 
66
79
  klass
67
80
  end
68
81
 
69
- def setup_class_attr_readers(klass)
70
- klass.send(:attr_reader, *args)
71
- klass.send(:public, *args) if args.any?
72
- end
73
-
74
- def setup_class_attr_writers(klass)
75
- klass.send(:attr_writer, *args)
76
- klass.send(:private, *args.map { |a| "#{a}=" }) if args.any?
82
+ def setup_class_accessors(klass)
83
+ ::EacRubyUtils::CommonConstructor::ClassAccessors.new(self, klass).perform
77
84
  end
78
85
 
79
86
  def setup_class_initialize(klass)
80
- klass.include(::ActiveSupport::Callbacks)
81
- klass.define_callbacks :initialize
82
- ::EacRubyUtils::CommonConstructor::ClassInitialize.new(self, klass).run
87
+ ::EacRubyUtils::CommonConstructor::ClassInitialize.new(self, klass).perform
83
88
  end
84
89
 
85
90
  def super_args
@@ -1,37 +1,70 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler'
4
+ require 'eac_ruby_utils/ruby/on_replace_objects'
4
5
 
5
6
  module EacRubyUtils
6
7
  module Ruby
7
8
  class << self
8
9
  # Executes a block in an environment when the variables BUNDLE* and RUBY* are removed.
9
- def on_clean_environment
10
- bundler_with_unbundled_env do
11
- on_clean_envvars('BUNDLE', 'RUBY') { yield }
12
- end
10
+ def on_clean_environment(&block)
11
+ OnCleanEnvironment.new(&block).perform
13
12
  end
14
13
 
15
- private
14
+ class OnCleanEnvironment
15
+ ENVVARS_PREFIXES_TO_CLEAN = %w[BUNDLE RUBY].freeze
16
+
17
+ attr_reader :block, :original_env
16
18
 
17
- def bundler_with_unbundled_env(&block)
18
- if ::Bundler.respond_to?(:with_unbundled_env)
19
- ::Bundler.with_unbundled_env(&block)
20
- else
21
- ::Bundler.with_clean_env(&block)
19
+ def initialize(&block)
20
+ @block = block
21
+ @original_env = ::ENV.to_h
22
22
  end
23
- end
24
23
 
25
- def on_clean_envvars(*start_with_vars)
26
- old_values = envvars_starting_with(start_with_vars)
27
- old_values.each_key { |k| ENV.delete(k) }
28
- yield
29
- ensure
30
- old_values&.each { |k, v| ENV[k] = v }
31
- end
24
+ # @return [Array<String>]
25
+ def envvars_prefixes_to_clean
26
+ ENVVARS_PREFIXES_TO_CLEAN
27
+ end
32
28
 
33
- def envvars_starting_with(start_with_vars)
34
- ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
29
+ def perform
30
+ bundler_with_unbundled_env do
31
+ on_clean_envvars
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def bundler_with_unbundled_env(&block)
38
+ with_bundler_modified do
39
+ ::Bundler.send(bundler_with_env_method_name, &block)
40
+ end
41
+ end
42
+
43
+ def bundler_with_env_method_name
44
+ if ::Bundler.respond_to?(:with_unbundled_env)
45
+ :with_unbundled_env
46
+ else
47
+ :with_clean_env
48
+ end
49
+ end
50
+
51
+ def clean_env
52
+ r = original_env.dup
53
+ r.delete_if { |k, _| envvars_prefixes_to_clean.any? { |prefix| k.start_with?(prefix) } }
54
+ r
55
+ end
56
+
57
+ def on_clean_envvars
58
+ ::Bundler.send('with_env', clean_env) { block.call }
59
+ end
60
+
61
+ def with_bundler_modified(&block)
62
+ cloned_env = original_env.dup
63
+ ::EacRubyUtils::Ruby.on_replace_objects do |replacer|
64
+ replacer.replace_self_method(::Bundler, :original_env) { cloned_env }
65
+ block.call
66
+ end
67
+ end
35
68
  end
36
69
  end
37
70
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/inflector'
4
+ require 'eac_ruby_utils/ruby/on_replace_objects/replace_instance_method'
5
+
6
+ module EacRubyUtils
7
+ module Ruby
8
+ class OnReplaceObjects
9
+ class ReplaceInstanceMethod
10
+ attr_reader :a_module, :method_new_block, :original_method
11
+
12
+ def initialize(a_module, method_name, &method_new_block)
13
+ @a_module = a_module
14
+ @original_method = a_module.instance_method(method_name)
15
+ @method_new_block = method_new_block
16
+ end
17
+
18
+ def apply
19
+ a_module.define_method(method_name, &method_new_block)
20
+
21
+ self
22
+ end
23
+
24
+ def method_name
25
+ original_method.name
26
+ end
27
+
28
+ def restore
29
+ a_module.define_method(method_name, original_method)
30
+
31
+ self
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/inflector'
4
+ require 'eac_ruby_utils/ruby/on_replace_objects/replace_instance_method'
5
+
6
+ module EacRubyUtils
7
+ module Ruby
8
+ class << self
9
+ def on_replace_objects
10
+ replacer = OnReplaceObjects.new
11
+ replacer.on_replacement do
12
+ yield(replacer)
13
+ end
14
+ end
15
+ end
16
+
17
+ class OnReplaceObjects
18
+ def on_replacement(&block)
19
+ clear_replacements
20
+ block.call(self)
21
+ ensure
22
+ restore_replacements
23
+ end
24
+
25
+ def replace_instance_method(a_module, method_name, &block)
26
+ add_replacement(__method__, a_module, method_name, &block)
27
+ end
28
+
29
+ def replace_self_method(object, method_name, &block)
30
+ add_replacement(:replace_instance_method, object.singleton_class, method_name, &block)
31
+ end
32
+
33
+ private
34
+
35
+ def add_replacement(method_name, *args, &block)
36
+ @replacements << replacement_class(method_name).new(*args, &block).apply
37
+ end
38
+
39
+ def replacement_class(method_name)
40
+ self.class.const_get(::ActiveSupport::Inflector.camelize(method_name))
41
+ end
42
+
43
+ def clear_replacements
44
+ @replacements = []
45
+ end
46
+
47
+ def restore_replacements
48
+ @replacements.reverse.each(&:restore)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.100.0'
4
+ VERSION = '0.102.0'
5
5
  end
@@ -93,6 +93,32 @@ RSpec.describe ::EacRubyUtils::CommonConstructor do
93
93
  end
94
94
  end
95
95
 
96
+ context 'with block argument' do
97
+ let(:instance) do
98
+ described_class.new(:first, :second, :last, block_arg: true, default: ['second'])
99
+ end
100
+
101
+ let(:block) do
102
+ ::Proc.new { first + second }
103
+ end
104
+
105
+ let(:a_class) do
106
+ ::Class.new do
107
+ def result
108
+ last.run
109
+ end
110
+ end
111
+ end
112
+
113
+ let(:a_class_instance) { a_class.new('first') { 'last' } }
114
+
115
+ it { expect(a_class_instance.last).to be_a(::Proc) }
116
+ it { expect(a_class_instance.last.call).to eq('last') }
117
+
118
+ it { expect(a_class_instance.first).to eq('first') }
119
+ it { expect(a_class_instance.second).to eq('second') }
120
+ end
121
+
96
122
  context 'with class hierarchy mixed with and without common_constructor' do
97
123
  let(:klass_0) do
98
124
  described_class.new(:a_param).setup_class(::Class.new)
@@ -6,9 +6,12 @@ RSpec.describe ::EacRubyUtils::Ruby do
6
6
  describe '#on_clean_environment' do
7
7
  let(:envvar_name) { 'BUNDLE_NOT_EXISTENT_ENV_VAR' }
8
8
  let(:envvar_value) { 'any value' }
9
+ let(:noruby_envvar_name) { 'ANY_ENVIRONMENT_VARIABLE' }
10
+ let(:noruby_envvar_value) { 'another any value' }
9
11
 
10
12
  before do
11
13
  ENV[envvar_name] = envvar_value
14
+ ENV[noruby_envvar_name] = noruby_envvar_value
12
15
  end
13
16
 
14
17
  it do # rubocop:disable RSpec/MultipleExpectations
@@ -18,5 +21,13 @@ RSpec.describe ::EacRubyUtils::Ruby do
18
21
  end
19
22
  expect(ENV[envvar_name]).to eq(envvar_value)
20
23
  end
24
+
25
+ it do # rubocop:disable RSpec/MultipleExpectations
26
+ expect(ENV[noruby_envvar_name]).to eq(noruby_envvar_value)
27
+ described_class.on_clean_environment do
28
+ expect(ENV[noruby_envvar_name]).to eq(noruby_envvar_value)
29
+ end
30
+ expect(ENV[noruby_envvar_name]).to eq(noruby_envvar_value)
31
+ end
21
32
  end
22
33
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/ruby'
4
+
5
+ RSpec.describe ::EacRubyUtils::Ruby do
6
+ describe '#on_replace_objects' do
7
+ let(:stub_class) do
8
+ ::Class.new do
9
+ def self.my_class_method
10
+ 'Original'
11
+ end
12
+
13
+ def my_instance_method
14
+ 'Original'
15
+ end
16
+ end
17
+ end
18
+
19
+ let(:stub_instance) { stub_class.new }
20
+
21
+ let(:replace_block) do
22
+ ::Proc.new { 'Replaced' }
23
+ end
24
+
25
+ describe '#my_instance_method' do
26
+ let(:before) { stub_instance.my_instance_method }
27
+ let(:inside) do
28
+ described_class.on_replace_objects do |replacer|
29
+ replacer.replace_instance_method(stub_class, :my_instance_method, &replace_block)
30
+ stub_instance.my_instance_method
31
+ end
32
+ end
33
+ let(:after) { stub_instance.my_instance_method }
34
+
35
+ before do
36
+ before
37
+ inside
38
+ after
39
+ end
40
+
41
+ it { expect(before).to eq('Original') }
42
+ it { expect(inside).to eq('Replaced') }
43
+ it { expect(after).to eq('Original') }
44
+ end
45
+
46
+ describe '#replace_self_method' do
47
+ let(:before) { stub_class.my_class_method }
48
+ let(:inside) do
49
+ described_class.on_replace_objects do |replacer|
50
+ replacer.replace_self_method(stub_class, :my_class_method, &replace_block)
51
+ stub_class.my_class_method
52
+ end
53
+ end
54
+ let(:after) { stub_class.my_class_method }
55
+
56
+ before do
57
+ before
58
+ inside
59
+ after
60
+ end
61
+
62
+ it { expect(before).to eq('Original') }
63
+ it { expect(inside).to eq('Replaced') }
64
+ it { expect(after).to eq('Original') }
65
+ end
66
+ end
67
+ end