Fix Array#flatten on an array containing a Settingslogic object...
...by delegating method_missing to Hash in the specific case.
On newer rubies, Array#flatten calls #to_ary on everything in the array, which raises a MissingSetting error from a Settingslogic object. This was reported as an rspec-core issue, but is more a ruby/settingslogic deal.
At any rate, you'd see an unhandled Settingslogic::MissingSetting: Missing setting 'to_ary' if you happened to have a Settingslogic object in an array that got flattened.
This is particularly a pain point with newer rspec. See https://github.com/rspec/rspec-core/issues/620 for the initial bug report, which was referred to Settingslogic for a fix. I concur.
My editor hates trailing whitespace, so that's redacted in there too :).
I'm +1 for this as it currently bites me.
+1 .. break my build too.
+1
+1
Interestingly, after monkey-patching this I got
/usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:173:in missing_key': Missing setting 'to_str' in /Users/glennr/git/blah/config/models/debit_order_rejection_settings.yml (Settingslogic::MissingSetting) from /Users/glennr/git/blah/spec/support/settingslogic_rspec1_hack.rb:14:inmethod_missing'
from /usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/settingslogic-2.0.8/lib/settingslogic.rb:77:in method_missing' from /usr/local/opt/rbenv/versions/1.9.3-p374/lib/ruby/gems/1.9.1/gems/rspec-1.3.1/lib/spec/example/example_group_hierarchy.rb:49:injoin'
So I ended up adding
super if name === :to_str # delegate to Hash
ie.
class Settingslogic < Hash
def method_missing(name, *args, &block)
super if name === :to_ary # delegate to Hash
super if name === :to_str # delegate to Hash
key = name.to_s
return missing_key("Missing setting '#{key}' in #{@section}") unless has_key? key
value = fetch(key)
create_accessor_for(key)
value.is_a?(Hash) ? self.class.new(value, "'#{key}' section in #{@section}") : value
end
end
+1
+1
+1
I got the same issue. +1
+1 from me, too.
Is there anything we can do to help get this merged?
+1 same issue here
+1
:+1:
:+1:
:+1: