Live data from Hacker News

Learn how to test Rails using Test::Unit instead of Rspec

whatdoitest.com

11–20 of 51 posts

Re: Learn how to test Rails using Test::Unit instead of Rspec

#11
post #8

My experience: I just started the process of converting our few hundred Test::Unit tests to Rspec simply because Test Unit documentation is terrible . Our tests need a lot of work and I'm not that experienced at writing test scripts. I have to learn this as I do it, and I struggled to find resources for learning Test::Unit. Every blog post, tutorial and guide I can find was written for Rspec. As much as I'd love to c…

"For me it was a simple decision: If I want community support, I need to be using the tool the community is actually supporting."

Truth. And the community is really split on this one. The side that makes the decisions about what goes into rails prefer unit tests, while a large chunk of the users prefer spec-based.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#12
> Just from skimming over the tests, it’s obvious that Rspec is more readable.

And that's where I'd disagree and my tastes differ, I never quite got the Ruby fetishism for almost-sort-kinda English DSLs. It's still baffling to non-developers and I'd much rather read a more regular programming language syntax, never mind that abusing the syntax can lead to some weird error messages. (Not saying that RSpec/Cucumber fall into that trap, as I never had that much experience with them. Like I said, kinda turn-off for me)

A bit like Lisp macro abuse or too much parsing in Tcl.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#13

I think the bigger issue here is that new developers of Rails don't understand the best practices for testing. I switched from PHP to Ruby, then learned rails over the past year and it had a significant learning curve. First I tried testing models and controllers, skipping views. Now I use integration tests with Capybara because it effectively tests the whole stack without writing redundant test code. What's not clea…

> First I tried testing models and controllers, skipping views. Now I use integration tests with Capybara because it effectively tests the whole stack without writing redundant test code.

Does this mean you primarily rely on integration tests at the exclusion of model unit tests?

If that's the case, I'm of the opinion you would be well served by revisiting your unit tests. Controller tests are kinda taken care of by integration tests, but you won't get solid coverage of your models with integration tests alone.

At a minimum, model unit + integration (skipping controllers), IMHO. If for no other reason than running an integration test suite can be time consuming, and you don't always need your feedback loop to be that long.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#14
post #12

> Just from skimming over the tests, it’s obvious that Rspec is more readable. And that's where I'd disagree and my tastes differ, I never quite got the Ruby fetishism for almost-sort-kinda English DSLs. It's still baffling to non-developers and I'd much rather read a more regular programming language syntax, never mind that abusing the syntax can lead to some weird error messages. (Not saying that RSpec/Cucumber fal…

Computers don't understand english very well. It's easier for us to learn to talk to them, than to teach them how to understand us.

DSLs are helpful for some, but sometimes they get in my way. A good example is formtastic (http://github.com/justinfrench/formtastic) in ActiveAdmin. I already understood forms when I had to implement this, so it just dragged me down.

If using a DSL makes your life easier, by all means use it.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#16
God yes.

Test::Unit is simple, comes baked in, and because it's not some faux-English DSL your brain isn't constantly fighting with itself making stupid and incorrect assumptions about syntax because 'hey, it looks like English'.

The worst testing-related decision I ever made was using Michael Hardt's Rails Tutorial (which has RSpec baked in) to learn Rails in the first place. Great tutorial otherwise, but it set my testing back immensely - it pretty much meant I did no testing at all. When I finally bit the bullet and decided to learn how to use Test::Unit, I was astounded at how easy it actually was.

Most Rails resources online assume familiarity with so many not-out-of-the-box tools it's a bloody miracle anyone can learn Rails at all. It's a real problem.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#17
post #13

I think the bigger issue here is that new developers of Rails don't understand the best practices for testing. I switched from PHP to Ruby, then learned rails over the past year and it had a significant learning curve. First I tried testing models and controllers, skipping views. Now I use integration tests with Capybara because it effectively tests the whole stack without writing redundant test code. What's not clea…

> First I tried testing models and controllers, skipping views. Now I use integration tests with Capybara because it effectively tests the whole stack without writing redundant test code. Does this mean you primarily rely on integration tests at the exclusion of model unit tests? If that's the case, I'm of the opinion you would be well served by revisiting your unit tests. Controller tests are kinda taken care of by…

I do integration tests + model tests

Re: Learn how to test Rails using Test::Unit instead of Rspec

#18

I think the bigger issue here is that new developers of Rails don't understand the best practices for testing. I switched from PHP to Ruby, then learned rails over the past year and it had a significant learning curve. First I tried testing models and controllers, skipping views. Now I use integration tests with Capybara because it effectively tests the whole stack without writing redundant test code. What's not clea…

My theory is that new Rails developers spend more time learning how to test than what to test. This article isn't necessarily about which framework is better, but more about which is better as a testing learning tool. It's been pretty cool working on the testing book because I'm approaching it from a different angle. I'm not testing something, I'm showing someone how to test. I've got to dig into Test::Unit and MiniT…

There's most definitely inefficient ways of testing. You can often cut the time of your testing if done right.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#19
post #5
post #2

I was a little disappointed in this article. What I've always wanted to know is: Why do Rails developers use Rspec when they can use MiniTest::Spec? I was hoping the OP would address that, since MiniTest is the default Ruby testing suite he refers to. Do Rails devs continue to use Rspec because it's what they're used to? Or is Rspec a dependency for other testing tools and libraries? I don't agree at all with this pr…

I started testing with Test::Unit+Shoulda, and then moved to RSpec when I found that it was basically the same thing with less hackery. This was being Minitest existed. Since then, I've stuck with RSpec because it's got a ton of community support, and consistently lets me write concise tests. I never feel like I have to unduly repeat myself with RSpec; I constantly felt like that when I was writing testunit tests.

Seconded; I love the community around RSpec, and it works perfectly well for me.

Re: Learn how to test Rails using Test::Unit instead of Rspec

#20

God yes. Test::Unit is simple, comes baked in, and because it's not some faux-English DSL your brain isn't constantly fighting with itself making stupid and incorrect assumptions about syntax because 'hey, it looks like English'. The worst testing-related decision I ever made was using Michael Hardt's Rails Tutorial (which has RSpec baked in) to learn Rails in the first place. Great tutorial otherwise, but it set my…

Yes! Michael Hardt's tutorial is the culprit for me as well.
Post reply on HN