<raz>
does spec have a macro hook or callback that fires when a test fails? i wanna capture logging at debug level and dump it to the screen when a test fails, but only then.
<raz>
`after_suite` might do what i want, but how do i find out whether it succeeded, hmm
<FromGitter>
<Blacksmoke16> not that im aware of
<raz>
will try an experiment with clearing log in before_each, after_each and dumping to screen in after_suite
<FromGitter>
<Blacksmoke16> dont think its exactly what you want tho
<raz>
hmm indeed, looks like it's not intended to actually print the log
<raz>
but well, the capturing part is easy anyway (MemoryBackend). just hope that `after_each` won't fire when a spec fails
<FromGitter>
<plambert> Can anyone quickly point me to an example of reading a JSON config file, that handles exceptions (missing file, malformed JSON, etc) well?
<FromGitter>
<plambert> By "well" I mean I want to create the file and dir path if they're missing, with default configs... and if it's malformed, I want to say it's malformed, not throw an exception and trace...
<FromGitter>
<plambert> Thanks, @Blacksmoke16
<FromGitter>
<Blacksmoke16> well you're going to need to handle most of that yourself
<FromGitter>
<Blacksmoke16> at least the former
<FromGitter>
<plambert> Right. I'm pretty sure I'm not the first person to do this, so I figured I'd look for an example of how someone else did it.
<FromGitter>
<plambert> My first pass at it isn't very elegant, and is very hard to follow...
<FromGitter>
<plambert> It's pretty ugly, and will be uglier when I add support for environment variables…
<FromGitter>
<plambert> I'm just trying to find a way to make it easier to follow
<FromGitter>
<Blacksmoke16> prob dont need to use pull parser in this context
<FromGitter>
<plambert> what do you recommend?
<FromGitter>
<Blacksmoke16> just have a config type with default values, then have your create method check if the file exists, if not to like `File.write path, Config.new.to_json`
<FromGitter>
<Blacksmoke16> otherwise do a `Config.from_json file_contents`
<FromGitter>
<plambert> OK, so I'd make a …::Config class, include JSON::Serializable and JSON::Serializable::Unmapped (because I want to preserve unknown keys), give it a read_file class method, and a write_file instance method... I think I get it.
<FromGitter>
<plambert> I'll give it a shot. Thanks for pointing me in that direction.
<FromGitter>
<Blacksmoke16> sounds good
<FromGitter>
<plambert> Hmm... I was trying to avoid as many nillable properties in my main object as I could...
<FromGitter>
<Blacksmoke16> give them default values then?
<FromGitter>
<plambert> But if I make a Config class, it'll have to allow things like token to be nilable
<FromGitter>
<plambert> There's no default value for an OAuth token, for example.
<FromGitter>
<Blacksmoke16> how did you have it not be nilable before then?
<FromGitter>
<Blacksmoke16> just using a hash?
<FromGitter>
<plambert> No, I call Thing.create instead of Thing.new
<FromGitter>
<plambert> And create reads the config file, and if there's no token, or the token is expired, does the OAuth stuff to get a new one
<FromGitter>
<plambert> *then* creates the Thing
<FromGitter>
<plambert> That way Thing.initialize can require the token exist and be valid, and I don't have to pepper my code with checks for nil
<FromGitter>
<Blacksmoke16> cant just include that logic in there still?
<FromGitter>
<Blacksmoke16> doesnt have to be `.new.to_json` `.create.to_json` would be fine too
<FromGitter>
<plambert> I'll think about it. There has to be a way. And what I'm doing now *works* so I can survive with it, it's just hard to follow
<FromGitter>
<Blacksmoke16> your current implementation could prob be easier if you just check if it exists first
<FromGitter>
<Blacksmoke16> and use `Hash(String, String).from_json contents`