Something is broken, for me at least, in 0.4.1 (and going back to 0.4.0
fixes it):
pegasus:~/src/gems/wrong-0.4.1> ruby test/assert_test.rb
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Test run options: --seed 47286
Loaded suite test/assert_test
Started
E.FF.FF
Finished in 0.007350 seconds.
1) Error:
test_0001_passes_when_the_result_is_true_deny_does_the_reverse(BasicAssertFeaturesSpec::PassFailBasicsSpec):
NoMethodError: private method `gsub' called for
#<Errno::ENOENT:0x7f9c77983800>
./test/../lib/wrong/config.rb:24:in `initialize'
./test/../lib/wrong/config.rb:10:in `new'
./test/../lib/wrong/config.rb:10:in `load_config'
./test/../lib/wrong/config.rb:14:in `config'
./test/../lib/wrong/assert.rb:91:in `aver'
./test/../lib/wrong/assert.rb:34:in `assert'
test/assert_test.rb:14:in
`test_0001_passes_when_the_result_is_true_deny_does_the_reverse'
This looks like the problem. I have no .wrong file, so settings is
assigned an instance of Errno::ENOENT.
$ diff -u wrong-0.4.0/lib/wrong/config.rb wrong-0.4.1/lib/wrong/config.rb
--- wrong-0.4.0/lib/wrong/config.rb 2010-10-04 11:42:19.543965812 -0700
+++ wrong-0.4.1/lib/wrong/config.rb 2010-10-07 16:35:52.512289503 -0700
@@ -1,9 +1,38 @@
+require "wrong/chunk"
+
module Wrong
+ def self.load_config
+ settings = begin
+ Chunk.read_here_or_higher(".wrong")
+ rescue Errno::ENOENT => e
+ # couldn't find it
+ end
+ Config.new settings
+ end
+
Nothing personal, but that code style reminds me of Python.
Throw first and ask questions later! C-:
I don't see what you mean. I see "foo = begin...end" all the time in Ruby. And this code is basically saying that the exception is not an error, but more like a return value ("no file"). Would you be happier if #read_here_or_higher caught the exception and returned nil?
>>> + Chunk.read_here_or_higher(".wrong")
>>> + rescue Errno::ENOENT => e
>> Nothing personal, but that code style reminds me of Python.
> I don't see what you mean. I see "foo = begin...end" all the time in Ruby. And this code is basically saying that the exception is not an error, but more like a return value ("no file"). Would you be happier if #read_here_or_higher caught the exception and returned nil?
Sorry - I'm just still chafing from my last job.
The Python community insists on - takes pride in - breaking the rule
"don't use exceptions for normal control flow". They would rather say
try-except than just 'if'.
In the case of file handling, if you said 'if file.exists?', then the
file could disappear in the split second between testing it and using
it (or it could have broken permissions). But still I always tried,
even in Python, to return None or [].
Don't mind me!
--
Phlip
http://c2.com/cgi/wiki?ZeekLand
fwiw I endorse this general sentiment!
Me too, in general. In this case it was actually the right thing to do
since we really tried to load a file; the contents were not "nil" but
there was actually an error so it's right for the lower-level function
to fail hard; and in this case (but not the other) we wanted to carry
on.
I would have done
load(file) if file.exists?
except there is no file.exists_here_or_in_some_ancestor? and it would
be silly to write it. Also the atomicity thing Phlip mentions.
--
Alex Chaffee - al...@stinky.com - http://alexch.github.com
Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch |
http://alexch.tumblr.com