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, &node_builder) ⇒ 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, &block) ⇒ Object
Class Method Details
.extended(obj) ⇒ Object
12 13 14 15 16 |
# File 'lib/eac_config/rspec/setup.rb', line 12 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
28 29 30 |
# File 'lib/eac_config/rspec/setup.rb', line 28 def envvars_load_path_entry ::EacConfig::EnvvarsNode.new.load_path.entry end |
#on_envvars_load_path_clean(example) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/eac_config/rspec/setup.rb', line 18 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, &node_builder) ⇒ Object
Wraps a RSpec example in a EacConfig node using a alternative file.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/eac_config/rspec/setup.rb', line 40 def stub_eac_config_node(target_example = nil, target_file = nil, &node_builder) 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, &node_builder)) do example.run end end end end |
#stub_eac_config_node_build(file, &node_builder) ⇒ Object
52 53 54 |
# File 'lib/eac_config/rspec/setup.rb', line 52 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, &block) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/eac_config/rspec/setup.rb', line 56 def stub_eac_config_node_on_file(target_file, &block) if target_file yield(target_file.to_pathname) else ::EacRubyUtils::Fs::Temp.on_file(&block) end end |