Learn how to test Rails using Test::Unit instead of Rspec
whatdoitest.com
Learn how to test Rails using Test::Unit instead of Rspec
1–10 of 51 posts
Re: Learn how to test Rails using Test::Unit instead of Rspec
#2I 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
#3I 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 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 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
#5I 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…
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
#6First 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
#7I 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…
Re: Learn how to test Rails using Test::Unit instead of Rspec
#8I 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
#9I 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…
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
#10My 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…