Module: EacConfig::Rspec::Setup
- Defined in:
- lib/eac_config/rspec/setup.rb
Class Method Summary collapse
Instance Method Summary collapse
- #envvars_load_path_entry ⇒ Object
- #on_envvars_load_path_clean(example) ⇒ Object
-
#stub_eac_config_node(target_example = nil, target_file = nil) ⇒ Object
Wraps a RSpec example in a EacConfig node using a alternative file.
- #stub_eac_config_node_build(file, &node_builder) ⇒ Object
- #stub_eac_config_node_on_file(target_file) ⇒ Object
Class Method Details
.extended(obj) ⇒ Object
6 7 8 9 10 |
# File 'lib/eac_config/rspec/setup.rb', line 6 def self.extended(obj) obj.rspec_config.around do |example| obj.on_envvars_load_path_clean(example) end end |
Instance Method Details
#envvars_load_path_entry ⇒ Object
22 23 24 |
# File 'lib/eac_config/rspec/setup.rb', line 22 def envvars_load_path_entry ::EacConfig::EnvvarsNode.new.load_path.entry end |
#on_envvars_load_path_clean(example) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/eac_config/rspec/setup.rb', line 12 def on_envvars_load_path_clean(example) old_value = envvars_load_path_entry.value begin envvars_load_path_entry.value = old_value = [] example.run ensure envvars_load_path_entry.value = old_value end end |
#stub_eac_config_node(target_example = nil, target_file = nil) ⇒ Object
Wraps a RSpec example in a EacConfig node using a alternative file.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/eac_config/rspec/setup.rb', line 34 def stub_eac_config_node(target_example = nil, target_file = nil, &) parent_self = self (target_example || rspec_config).around do |example| parent_self.stub_eac_config_node_on_file(target_file) do |file| ::EacConfig::Node .context.on(parent_self.stub_eac_config_node_build(file, &)) do example.run end end end end |
#stub_eac_config_node_build(file, &node_builder) ⇒ Object
46 47 48 |
# File 'lib/eac_config/rspec/setup.rb', line 46 def stub_eac_config_node_build(file, &node_builder) node_builder.present? ? node_builder.call(file) : ::EacConfig::YamlFileNode.new(file) end |
#stub_eac_config_node_on_file(target_file) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/eac_config/rspec/setup.rb', line 50 def stub_eac_config_node_on_file(target_file, &) if target_file yield(target_file.to_pathname) else ::EacRubyUtils::Fs::Temp.on_file(&) end end |