Re:Learn how to test Rails using Test::Unit instead of Rspec
by aaronbrethorst on Thursday March 21, 2013 @04:04PM
(#5418460)
I hate to be that guy, but the Rspec tests should be written more like the following:
Note: I almost certainly misinterpreted the first Regex. 'now you have two problems,' etc. etc.
[ Parent
| on HN ]
Re:Learn how to test Rails using Test::Unit instead of Rspec
by pklingem on Thursday March 21, 2013 @05:09PM
(#5419027)
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
Re:Learn how to test Rails using Test::Unit instead of Rspec
by pjungwir on Thursday March 21, 2013 @05:29PM
(#5419194)
I like and use RSpec, but I think these improvements are proving the guy's point that its DSL is forbidding for beginners. I write RSpec more like the original post because it's less magic.
Re:Learn how to test Rails using Test::Unit instead of Rspec
by reyan on Thursday March 21, 2013 @05:31PM
(#5419218)
Not really. At least RSpec's creator doesn't think so (http://blog.davidchelimsky.net/2012/05/13/spec-smell-explici...).
Re:Learn how to test Rails using Test::Unit instead of Rspec
by aaronbrethorst on Thursday March 21, 2013 @06:57PM
(#5419898)
neat, I didn't know you could do that. thanks for sharing!
Re:Learn how to test Rails using Test::Unit instead of Rspec
by richardjordan on Thursday March 21, 2013 @04:50PM
(#5418883)
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
by reyan on Thursday March 21, 2013 @05:33PM
(#5419227)
Even better with the new syntax:
expect(article.slug).to match(/[^\w-]/)
Re:Learn how to test Rails using Test::Unit instead of Rspec
by ratbeard on Thursday March 21, 2013 @08:37PM
(#5420524)
I didn't understand why the author used the unnecessary regex assertions, which are less clear and don't add any additional checks beyond:
article.slug.should == "testing-with-test-unit"
Re:Learn how to test Rails using Test::Unit instead of Rspec
by warmwaffles on Thursday March 21, 2013 @04:51PM
(#5418896)
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.