B
Bil Kleb
. hi-jacking at_exit sucks ass
IIRC, PragDave suggested the at_exit trick to Talbott during
the elder days.
Later,
. hi-jacking at_exit sucks ass
Just a thought: I've found myself doing that too, but in particular I've
ran an example externally to be sure it works, then ended up pasting it
into the rdoc. So it would be really cool if rdoc could integrate the
examples directly in the appropriate place(s). I want to be sure that my
examples actually run as advertised, and at the moment I risk them
becoming out of date, so I'm definitely with you on that point.
Bil said:
Brian said:Ah, now that's a really interesting way of thinking about
examples/testing: in the form of an irb session. You can write your
tests just by mucking about in irb, and when it makes sense, just paste
the output somewhere.
irb> foo = generate_foo
=> #<Foo:0xb7cd041c @attr1="hello", @attr2="world">
irb> foo.attr1
=> "hello"
irb> foo.attr2
=> "world"
Perhaps - but it's one rule that only needs to be learned once.
I notice that testy supports check <name>, <expected>, <actual> too.
Testy does (intentially) force you to name your tests, whereas
Test::Unit will happily let you write
check <expected>, <actual>
I really don't like having to name each assertion, maybe because I'm
lazy or maybe because it feels like DRY violation. I've already said
what I want to compare, why say it again?
Hmm, this is probably an argument *for* having a DSL for assertions
- to
make the assertions read as much like example code ("after running
this
example, you should see that A == B and C < D")
Neither
result.check "bar attribute", :expected => 123, :actual => res.bar
nor
assert_equal 123, res.bar, "bar attribute"
reads particularly well here, I think.
Going too far this way down this path ends up with rspec, I think.
In fact, I don't really have a problem with writing
res.foo.should == 456
The trouble is the hundreds of arcane variations on this.
You solve this problem by only having a single test (Result#check),
and
indeed if rspec only had a single method (should_equal) that would be
fairly clean too. However this is going to lead to awkwardness when
you
want to test for something other than equality: e.g.
result.check "foo should contain 'error'", foo, :=~, /error/
But again this is getting away from real ruby for the assertions, in
which case it isn't much better than
assert_match /error/, foo, "foo should contain 'error'"
assert_match /error/, foo # lazy/DRY version
Yes, parseable results and test management are extremely beneficial.
Those could be retro-fitted to Test::Unit though (or whatever its
replacement in ruby 1.9 is called)
Getting rid of the at_exit magic is also worth doing.
Nice, could perhaps show the (expected) result inline too?
I agree. Part of the problem is that when one thing is wrong making 20
tests fail, all with their respective backtraces, it can be very
hard to
see the wood for the trees. What would be nice would be a folding-type
display with perhaps one line for each failed assertion, and a [+] you
can click on to get the detail for that particular one.
I disagree there - not with the research, but the implied conclusion
that you should never use a large codebase. Shoulda works well, and
I've
not once found a bizarre behaviour in the testing framework itself
that
I've had to debug, so I trust it.
Yeah, but how many lines of Rails framework?
Perhaps - but it's one rule that only needs to be learned once.
i'm open to suggestion on format though. =A0requirements are
=A0 =A0 =A0 =A0 . readable by humans
=A0 =A0 =A0 =A0 =A0. easily parsed by computers
basically that means some yaml format. =A0honestly open to suggestion =A0
here...
i have major issues with points two and three wrst to most ruby =A0
testing frameworks. =A0one of the main points of testy is to combine =A0
examples with testing. =A0rspec and all the others do not serve as =A0
examples unless you are a ruby master. =A0that is to say they introduce = =A0
too many additions to the code that's supposed to be an example to =A0
really preserve it's 'exampleness'. =A0and of course the output is =A0
utterly useless to normal humans. =A0if a framework provides 1000 =A0
asset_xxxxxxxx methods ad nausea then the point of the code - it's =A0
level of example-good-ness - is lost to mere mortals
this will summarize where my thoughts are on that
cfp:~/redfission > find vendor/gems/{faker,mocha,thoughtbot}* -type f|
xargs -n1 cat|wc -l
=A0 =A0 24255
cfp:~/redfission > find app -type f|xargs -n1 cat|wc -l
=A0 =A0 =A01828
rspec and co might be fine but seriously, the above is insane right?
I disagree. I 'learn' it each time I look at it, and then I forget it.
I think possibly because I think it's backwards.
The same goes for alias_method for me. I cannot tell you how many
times I've had to look up the order of old_name/new_name. And with
this, it's certainly because I think the values are backwards. (I just
had to look up the order to be sure.)
Ara said:100% agree on both counts. i personally would always use the options
approach expected, :actual =>) because of that.
Ara said:shoulda does work well - i stole it's context concept just yesterday ;-)
Phlip said:Who was just fussing about "too many lines of code in the framework"?
Right:
report = journal do
my_code()
end
Inside journal{}, everything the Ruby VM does gets packed into a report.
Then you rip the report to get back to your details. That's what assert{
2.0 } _can't_ do, so it goes in two passes.
The first pass is a normal block.call, to detect success or failure.
This is so any bugs in the second pass don't throw the test run.
The second pass puts the block into Ripper to decompile it, and then the
fun starts.
Joel said:So you have to be careful in the block to avoid side effects, right?
Otherwise pass1 and pass2 might start with different state.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.