Live data from Hacker News

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

whatdoitest.com

21–30 of 51 posts

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

#21

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 spac…

Not at all. Feel free to be _that_ guy. First thing I noticed about the example was that it was badly written RSpec - which undermines an article advising on what you should/shouldn't do for testing.

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

#23

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 spac…

I agree with you, I can't stand when I see @article and stuff strewn through out the tests. It's just asking for test pollution.

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

#24
Fundamentally disagree with much of this article. Not just what _that_ guy said: https://news.ycombinator.com/item?id=5418460

When I learned Rails a few years ago, I was learning programming from scratch apart from some very early fumblings in BASIC and FORTRAN 20 years ago now. I was completely unfamiliar with the idea of testing. I had to learn it from the ground up. RSpec wasn't just more understandable it was, and remains, better documented. It's not just the official documentation. It's that there are tons of examples of how to test different use cases, what one should test, best practices.

Learning to test isn't just learning literally what a few methods do. It's understanding how to use those in myriad mix and match situations in order to provide good test coverage.

RSpec is easier to read before the test, it produces beautiful output that is readable and expressive, when you write good tests and test the right things.

After trying to struggle with Test::Unit and writing uncovered code for long stretches because I couldn't understand what to do, and then discovering RSpec, reading great blog posts, write-ups and documentation on it and finding comfort in RED-GREEN-REFACTOR I would only recommend RSpec for someone starting from scratch, as I did.

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

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

This was my experience too. I tried to use Test::Unit because I was learning from scratch, Rails 2.something, and Test::Unit was "The Rails Way". But I was fumbling in the dark. The community around RSpec picked me up and carried me to the testing promised land.

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

#26

Fundamentally disagree with much of this article. Not just what _that_ guy said: https://news.ycombinator.com/item?id=5418460 When I learned Rails a few years ago, I was learning programming from scratch apart from some very early fumblings in BASIC and FORTRAN 20 years ago now. I was completely unfamiliar with the idea of testing. I had to learn it from the ground up. RSpec wasn't just more understandable it was, an…

Oh... and I cannot recommend this resource highly enough.

As RSpec documentation goes this set of slides open in a window will help you tremendously:

http://kerryb.github.com/iprug-rspec-presentation/#1

It uses simple example and hits all the major points well.

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

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

>I am dreading the technical debt I have in test-unit, and meanwhile the (Rails) world is moving on to Minitest

Minitest and Test::Unit are part of the same package since 1.9, with Test::Unit implemented as a simple compatibility layer on top of Minitest:

http://www.rubyinside.com/a-minitestspec-tutorial-elegant-sp...

The Minitest assertions are quite similar to the old Test::Unit assertions, a large number are identical:

http://rubydoc.info/stdlib/minitest/1.9.3/MiniTest/Assertion...

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

#29
You do realize that if you're using Ruby 1.9+ you're actually using Minitest, right? It's just a backwards compatible API. Don't confuse people with all the talk about Test::Unit.

Minitest::Spec is just an RSpec-like DSL built on top of Minitest, which is the successor to Test::Unit.

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

#30

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 spac…

one step further:

    describe Article do
      describe '#slug' do
        before do
          subject.title = "Testing with Test::Unit"
        end

        its(:slug) { should_not match(/[^\w-]/) }
        its(:slug) { should_not match(/[A-Z]/) }
        it 'replaces spaces with hyphens'
      end
    end
Post reply on HN