Live data from Hacker News

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

whatdoitest.com

1–10 of 51 posts

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

#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 premise by the OP:

> Just from skimming over the tests, it’s obvious that Rspec is more readable. The Rspec DSL was designed for us humans to be able to understand what is happening at a glance. This is where Rspec gets my vote. Unfortunately, we aren’t talking about reading or sharing tests. We are talking about writing tests, and this is where Rspec has a heafty learning curve.

I think the MiniTest::Spec API is both easy to read and write...(I'm assuming the OP is criticizing both Rspec and MiniTest::Spec here). I'm just saying this from personal experience, as I learned both the Spec and standard testing syntax at the same time.

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

#3
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…

OP here. MiniTest::Spec is great, and knocks out two of my complaints in the article: * Expectations are readable and writable * The docs are very easy to digest: http://bfts.rubyforge.org/minitest/MiniTest/Expectations.htm...

I don't recommend MiniTest::Spec for the same reason I didn't recommend Rspec. It requires some extra configuration out of the box. The actual process of switching from Rspec to Test::Unit went Rspec -> MiniTest -> Test::Unit. There's just more stuff that's neccessary to start writing tests.

It's the same reason that new rails devs shouldn't swap out ERB with HAML before they build their first application. Get to know the defaults, then decide.

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

#4
I hate to be that guy, but the Rspec tests should be written more like the following:

    describe 'Article' do
      let(:article) { Article.new }
  
      describe '#slug' do
        before(:each) do
          article.title = "Testing with Test::Unit"
        end
  
        it 'does not contain non-alphabetical characters' do
          article.slug.should_not match(/[^\w-]/)
        end
    
        it 'does not contain capital letters' do
          article.slug.should_not match(/[A-Z]/)
        end
    
        it 'replaces spaces with hyphens'
      end
    end
Note: I almost certainly misinterpreted the first Regex. 'now you have two problems,' etc. etc.

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

#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.

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

#6
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 clear is the pros and cons of each approach. Over time you end up using your own approach that works best for you. It's one thing to know that you need to "test your code", but with all the various testing libraries created, it can quickly become overwhelming.

In an ideal world, I'd like to learn more about the various approaches. Test::Unit vs Rspec, vs all the additional testing add-ons and how everything works together. When you end up spending just as much time writing tests as you do writing code, you quickly realize how critical getting the right approach to testing really is.

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

#7
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 use TDD most of the time when I'm developing, when I'm writing tests I'm really writing specs. I'm almost thinking out loud, what is this thing I'm about to create actually supposed to do? When writing like this the rspec syntax is far more natural, it matches the internal dialogue that's going on in my head. And the syntax is designed to encourage exactly this, thinking about the code you're about to write as though you were describing it to someone else.

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

#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 continue using Test::Unit and save myself the hassle of converting from one to the other, I found learning Test::Unit to be one giant brick wall after another.

No one is discussing it, no one is blogging about it, no one is writing stack overflow questions about the issues. (I say, in a discussion about a blog post about it... but this is the exception not the rule, sadly)

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

(Not that Rspec documentation is that much better-- I've now resorted to just reading public github repos and looking for spec/ directories to scrutinize and learn from. If anyone has links to any good repos that use rspec tests, I'd love it if you could send them my way! I need more good repos to learn from!)

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

#9

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 MiniTest more than I ever have, and it's been great.

There isn't a wrong way to test, so long as tests are being written.

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

#10
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…

Hear hear. I am dreading the technical debt I have in test-unit, and meanwhile the (Rails) world is moving on to Minitest and the world appears to be settling on Rspec syntax regardless. Nowhere to be found is even a conversion HOWTO, so test-unit starts feeling even more like a ghetto, and increases my conversion anxiety, which is all too bad, since I like what I consider to be the simplicity of test-unit.
Post reply on HN