-
-
Notifications
You must be signed in to change notification settings - Fork 61
Description
This is a question regarding a Ruby (not Rails) command-line program with RSpec tests.
This configuration file exists at ~/.treeconfig.yml and inside the project at config/treeconfig.yml.
test:
git_timeout: 7
verbosity: 2
default_roots:
- my_gems
- my_plugins
development:
git_timeout: 7
verbosity: 2
default_roots:
- my_gems
- my_plugins
production:
git_timeout: 300
verbosity: 2
default_roots: [sites, sitesUbuntu, work]The RSpec test is:
require "anyway/testing"
require_relative "../spec_helper"
describe GitTree::GTConfig, type: :config do
context "when the environment is not set" do
Anyway::Settings.current_environment = nil
it "raises an error" do
Anyway::Settings.current_environment = nil
expect { config }.to raise_error(RuntimeError, /Anyway::Settings environment/)
end
end
context "when the environment is set" do
Anyway::Settings.current_environment = "test"
it "does not raise an error" do
expect { config }.not_to raise_error
end
end
context "with attributes" do
Anyway::Settings.current_environment = "test"
config = described_class.new
config.load_from_sources([
{ type: :yml }, # Loads from this YAML file
{ type: :env } # Then overrides from ENV (e.g., MYAPP_HOST)
], config_path: 'config/treeconfig.yml')
...Only the last test shown has any issues; the preceding tests pass.
Notice the last statement above. I had to add config_path: option to the parameter list.
It does not seem to matter what goes there; at first the value I provided was config/treeconfig.yml. The docs do not mention this option, but whatever it is for, apparently it was called path before.
I get this error when RSpec runs:
An error occurred while loading ./spec/git_tree/gt_config_spec.rb.
Failure/Error:
config.load_from_sources([
{ type: :yml }, # Loads from this YAML file
{ type: :env } # Then overrides from ENV (e.g., MYAPP_HOST)
], config_path: 'config/treeconfig.yml')
TypeError:
no implicit conversion of String into Integer
# ./spec/git_tree/gt_config_spec.rb:25:in 'block (2 levels) in <top (required)>'
# ./spec/git_tree/gt_config_spec.rb:22:in 'block in <top (required)>'
# ./spec/git_tree/gt_config_spec.rb:4:in '<top (required)>'
# ./binstub/rspec:16:in 'Kernel#load'
# ./binstub/rspec:16:in '<main>'
Looking at anyway_config-2.7.2/lib/anyway/loaders/yaml.rb we see:
def parse_yml(path)
return {} unless File.file?(path)parse_yml is called with path set to config/treeconfig.yml/treeconfig.yml,
which looks like an error.
If I change the final parameter for load_from_sources to config_path: 'config' I get a different error:
Failure/Error: { type: :yml }, # Loads from this YAML file
ArgumentError:
missing keyword: :env_prefix
# ./spec/git_tree/gt_config_spec.rb:26:in 'block (2 levels) in <top (required)>'
# ./spec/git_tree/gt_config_spec.rb:23:in 'block in <top (required)>'
# ./spec/git_tree/gt_config_spec.rb:4:in '<top (required)>'
# ./binstub/rspec:16:in 'Kernel#load'
# ./binstub/rspec:16:in '<main>'