The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby Stub Variations

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jay Fields

Posts: 765
Nickname: jayfields
Registered: Sep, 2006

Jay Fields is a software developer for ThoughtWorks
Ruby Stub Variations Posted: Sep 11, 2006 12:32 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jay Fields.
Original Post: Ruby Stub Variations
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jay Fields
Latest Posts From Jay Fields Thoughts

Advertisement
The majority of my Unit Tests focus on testing individual classes one method or behavior at a time. To facilitate this type of testing the class under test often collaborates with stub classes. Ruby offers several choices for stubbing.

To demonstrate usage for the various types of stubs I'll use a test from our test suite and show the differing implementations. The example comes from our tests that ensure our SQL DSL behaves as expected. This test verifies that to_sql is called on the object that is in the block being passed to the values method and the return value of to_sql is appended to the sql being generated by the Insert instance.
def test_values_are_appened_to_insert_statement
statement = Insert.into[:table_name].values do
Select[:column1, :column2].from[:table2]
end
assert_equal "insert into table_name select column1, column2 from table2", statement.to_sql
end
The above code uses both the Insert and Select classes within the test. Using both classes does produce a passing test. However, a more robust implementation would allow the behavior of Select to be changed without breaking any of the tests within Insert. The next several entries will focus on the various types of stubs I've used in the past to solve this issue.

Read: Ruby Stub Variations

Topic: AjaxScaffold: Rails Generator for Firefox 1+, IE 6+ & Safari Previous Topic   Next Topic Topic: Coming Up for Air

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use