Patrick J. Collins
2011-Jun-12 16:26 UTC
[rspec-users] testing framework in 44 lines of ruby
Hi everyone, I just came across this post and was wondering if this is on target with how RSpec works under the hood? http://www.skorks.com/2011/02/a-unit-testing-framework-in-44-lines-of-ruby/ Patrick J. Collins http://collinatorstudios.com
On Jun 12, 2011, at 11:26 AM, Patrick J. Collins wrote:> Hi everyone, > > I just came across this post and was wondering if this is on target with how > RSpec works under the hood? > > http://www.skorks.com/2011/02/a-unit-testing-framework-in-44-lines-of-ruby/What do you mean by "on target"? Are you asking if the implementations are the same, or similar? Or are you asking if attest meets the same goals as RSpec? If you''re asking about implementation, you can see both implementations on github and judge for yourself: https://github.com/rspec/rspec-core https://github.com/rspec/rspec-expectations https://github.com/rspec/rspec-mocks https://github.com/skorks/attest If you look at the latter, you''ll see that the blog post''s title is at least a bit misleading. The https://github.com/skorks/attest/blob/master/lib/attest directory has 5 subdirectories and 6 files, one of which (https://github.com/skorks/attest/blob/master/lib/attest/execution_context.rb) is close to 200 lines long. I''ll leave it to somebody else to do a more thorough LOC comparison, but you get my drift. Cheers, David
Patrick J. Collins
2011-Jun-12 17:52 UTC
[rspec-users] testing framework in 44 lines of ruby
> What do you mean by "on target"? Are you asking if the implementations are > the same, or similar? Or are you asking if attest meets the same goals as > RSpec?More specifically, I meant the way he implements describe blocks and the should method... It''s difficult for me to tell from glancing through the actual RSpec code.. For example I am confused by the implementation of ''should'', since it calls: __should_for_example_group__ But prior to that, it appears that __should_for_example_group__ is an alias for should, which looks to me like it would be recursively calling itself. In that post''s example, their definition of should simply returns self as they described "it''s just syntactic sugar to make the tests read better", but from looking at RSpec''s code, it seems like there''s a lot more going on, but I am not quite seeing the big picture... Patrick J. Collins http://collinatorstudios.com
On Jun 12, 2011, at 12:52 PM, Patrick J. Collins wrote:>> What do you mean by "on target"? Are you asking if the implementations are >> the same, or similar? Or are you asking if attest meets the same goals as >> RSpec? > > More specifically, I meant the way he implements describe blocks and the should > method... > > It''s difficult for me to tell from glancing through the actual RSpec code.. > For example I am confused by the implementation of ''should'', since it calls: > __should_for_example_group__ > > But prior to that, it appears that __should_for_example_group__ is an alias for > should, which looks to me like it would be recursively calling itself.The code you''re looking at is an extension to support one liners like this: it { should do_something } The original definition of should is in https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/expectations/extensions/kernel.rb, which is what adds the ''should'' method to every object.> In that post''s example, their definition of should simply returns self as they > described "it''s just syntactic sugar to make the tests read better", but from > looking at RSpec''s code, it seems like there''s a lot more going on, but I am > not quite seeing the big picture...RSpec''s ''should'' actually does something: it accepts a matcher and then tells the matcher to "match" against self. So no, they are not doing the same thing. I''m not really sure what you''re trying to evaluate here, but feel free to ask if you have any more specific questions. Cheers, David
On Jun 12, 2011, at 10:52 AM, Patrick J. Collins wrote:>> What do you mean by "on target"? Are you asking if the implementations are >> the same, or similar? Or are you asking if attest meets the same goals as >> RSpec? > > More specifically, I meant the way he implements describe blocks and the should > method... > > It''s difficult for me to tell from glancing through the actual RSpec code..Don''t glance at it! Study it :) Pat