daze wrote in post #970699:
On Dec 25, 11:44pm, Marnen Laibow-Koser [email protected] wrote:
daze wrote in post #970694:
Alright. Here’s one roadblock.
So what I understand w/BDD is that I should write all these tests,
watch them fail, and then code to make the tests pass.
No. Write one test, watch it fail, make it pass, refactor as
necessary. Then write the next test. Lather, rinse, repeat.
Does this apply to all tests - unit, functional, etc? I got my unit
tests working, but my functionals are not.
Yes. One test at a time on each level. Also, Test::Unit functionals
are needlessly painful. Use Cucumber instead.
My usual procedure:
Write a Cucumber story for functionality, watch it fail.
Figure out the first thing I need to do to implement that functionality,
write a unit spec in RSpec, watch it fail, make it pass.
Do next unit spec likewise.
When Cucumber story passes, feature is complete. Write another story.
But the error
messages I get from running tests don’t provide as much insight as
doing “rails server” and then seeing whatever error comes up… I
don’t understand how people do this.
Probably by writing more atomic tests. Could you give an example test
that wasn’t as useful as you would have liked?
Sure. Navigating to a sections#show page yields a screen that says
“NoMethodError in SectionsController#show
undefined method `paginate’ for #Class:0x5eb4ad0”
so I immediately realize I need to check wherever I call paginate and
see if the method is implemented.
Running the functional test
ruby -I test test/functional/sections_controller_test.rb
Only yields this:
- Error:
test: A section should respond with 200.
“A section”? Which one? Make your descriptions more explicit.
(SectionsControllerTest):
NoMethodError: undefined method `response_code’ for nil:NilClass
This doesn’t mean anything to me.
How can that not mean anything to you, when it’s telling you exactly
what the error is?
(In my test, I had should
respond_with :success.)
You can step through with the debugger to see where it fails.
Also, RSpec and Cucumber have better error reporting than Test::Unit.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Sent from my iPhone
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Sent from my iPhone