5 ms·
I hate to be that guy, but the Rspec tests should be written more like the following: describe 'Article' do let(:article) { Article.new } de
by aaronbrethorst 14y ago
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.
- richardjordan 14y agoNot 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.
- warmwaffles 14y agoI 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.
- pklingem 14y agoone 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
- pjungwir 14y agoI 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.
- reyan 14y agoNot really. At least RSpec's creator doesn't think so (http://blog.davidchelimsky.net/2012/05/13/spec-smell-explicit-use-of-subject/ http://blog.davidchelimsky.net/2012/05/13/spec-smell-explici...).
- aaronbrethorst 14y agoneat, I didn't know you could do that. thanks for sharing!
- reyan 14y agoEven better with the new syntax: expect(article.slug).to match(/[^\w-]/)
- ratbeard 14y agoI 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"