codders-feedzirra 0.2.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +9 -0
  4. data/Gemfile +10 -0
  5. data/Guardfile +6 -0
  6. data/HISTORY.md +25 -0
  7. data/README.md +179 -0
  8. data/Rakefile +6 -0
  9. data/feedzirra.gemspec +28 -0
  10. data/lib/feedzirra.rb +17 -0
  11. data/lib/feedzirra/core_ext.rb +3 -0
  12. data/lib/feedzirra/core_ext/date.rb +19 -0
  13. data/lib/feedzirra/core_ext/string.rb +9 -0
  14. data/lib/feedzirra/core_ext/time.rb +29 -0
  15. data/lib/feedzirra/feed.rb +382 -0
  16. data/lib/feedzirra/feed_entry_utilities.rb +65 -0
  17. data/lib/feedzirra/feed_utilities.rb +72 -0
  18. data/lib/feedzirra/parser.rb +20 -0
  19. data/lib/feedzirra/parser/atom.rb +29 -0
  20. data/lib/feedzirra/parser/atom_entry.rb +30 -0
  21. data/lib/feedzirra/parser/atom_feed_burner.rb +21 -0
  22. data/lib/feedzirra/parser/atom_feed_burner_entry.rb +31 -0
  23. data/lib/feedzirra/parser/google_docs_atom.rb +28 -0
  24. data/lib/feedzirra/parser/google_docs_atom_entry.rb +29 -0
  25. data/lib/feedzirra/parser/itunes_rss.rb +50 -0
  26. data/lib/feedzirra/parser/itunes_rss_item.rb +32 -0
  27. data/lib/feedzirra/parser/itunes_rss_owner.rb +12 -0
  28. data/lib/feedzirra/parser/rss.rb +22 -0
  29. data/lib/feedzirra/parser/rss_entry.rb +34 -0
  30. data/lib/feedzirra/parser/rss_feed_burner.rb +22 -0
  31. data/lib/feedzirra/parser/rss_feed_burner_entry.rb +40 -0
  32. data/lib/feedzirra/version.rb +3 -0
  33. data/spec/benchmarks/feed_benchmarks.rb +98 -0
  34. data/spec/benchmarks/feedzirra_benchmarks.rb +40 -0
  35. data/spec/benchmarks/fetching_benchmarks.rb +28 -0
  36. data/spec/benchmarks/parsing_benchmark.rb +30 -0
  37. data/spec/benchmarks/updating_benchmarks.rb +33 -0
  38. data/spec/feedzirra/feed_entry_utilities_spec.rb +52 -0
  39. data/spec/feedzirra/feed_spec.rb +599 -0
  40. data/spec/feedzirra/feed_utilities_spec.rb +150 -0
  41. data/spec/feedzirra/parser/atom_entry_spec.rb +86 -0
  42. data/spec/feedzirra/parser/atom_feed_burner_entry_spec.rb +47 -0
  43. data/spec/feedzirra/parser/atom_feed_burner_spec.rb +47 -0
  44. data/spec/feedzirra/parser/atom_spec.rb +51 -0
  45. data/spec/feedzirra/parser/google_docs_atom_entry_spec.rb +22 -0
  46. data/spec/feedzirra/parser/google_docs_atom_spec.rb +31 -0
  47. data/spec/feedzirra/parser/itunes_rss_item_spec.rb +48 -0
  48. data/spec/feedzirra/parser/itunes_rss_owner_spec.rb +18 -0
  49. data/spec/feedzirra/parser/itunes_rss_spec.rb +54 -0
  50. data/spec/feedzirra/parser/rss_entry_spec.rb +85 -0
  51. data/spec/feedzirra/parser/rss_feed_burner_entry_spec.rb +85 -0
  52. data/spec/feedzirra/parser/rss_feed_burner_spec.rb +52 -0
  53. data/spec/feedzirra/parser/rss_spec.rb +49 -0
  54. data/spec/sample_feeds/AmazonWebServicesBlog.xml +796 -0
  55. data/spec/sample_feeds/AmazonWebServicesBlogFirstEntryContent.xml +63 -0
  56. data/spec/sample_feeds/FeedBurnerUrlNoAlternate.xml +27 -0
  57. data/spec/sample_feeds/GoogleDocsList.xml +187 -0
  58. data/spec/sample_feeds/HREFConsideredHarmful.xml +313 -0
  59. data/spec/sample_feeds/HREFConsideredHarmfulFirstEntry.xml +22 -0
  60. data/spec/sample_feeds/PaulDixExplainsNothing.xml +174 -0
  61. data/spec/sample_feeds/PaulDixExplainsNothingAlternate.xml +174 -0
  62. data/spec/sample_feeds/PaulDixExplainsNothingFirstEntryContent.xml +19 -0
  63. data/spec/sample_feeds/PaulDixExplainsNothingWFW.xml +174 -0
  64. data/spec/sample_feeds/TechCrunch.xml +1514 -0
  65. data/spec/sample_feeds/TechCrunchFirstEntry.xml +9 -0
  66. data/spec/sample_feeds/TechCrunchFirstEntryDescription.xml +3 -0
  67. data/spec/sample_feeds/TenderLovemaking.xml +515 -0
  68. data/spec/sample_feeds/TenderLovemakingFirstEntry.xml +66 -0
  69. data/spec/sample_feeds/TrotterCashionHome.xml +610 -0
  70. data/spec/sample_feeds/atom_with_link_tag_for_url_unmarked.xml +30 -0
  71. data/spec/sample_feeds/itunes.xml +60 -0
  72. data/spec/sample_feeds/run_against_sample.rb +20 -0
  73. data/spec/sample_feeds/top5kfeeds.dat +2170 -0
  74. data/spec/sample_feeds/trouble_feeds.txt +16 -0
  75. data/spec/spec_helper.rb +75 -0
  76. metadata +203 -0
@@ -0,0 +1,66 @@
1
+ <p>Oops! When I released <a href="http://nokogiri.rubyforge.org/" onclick="javascript:urchinTracker ('/outbound/article/nokogiri.rubyforge.org');">nokogiri</a> version 1.0.7, I totally forgot to talk about Nokogiri::Slop() feature that was added. Why is it called "slop"? It lets you sloppily explore documents. Basically, it decorates your document with method_missing() that allows you to search your document via method calls.</p>
2
+ <p>Given this document:</p>
3
+ <div class="codesnip-container" >
4
+ <div class="codesnip" style="font-family: monospace;">doc = Nokogiri::Slop<span class="br0">&#40;</span>&lt;&lt;-eohtml<span class="br0">&#41;</span><br />
5
+ &lt;html&gt;<br />
6
+ &nbsp; &lt;body&gt;<br />
7
+ &nbsp; &nbsp; &lt;p&gt;hello&lt;/p&gt;<br />
8
+ &nbsp; &nbsp; &lt;p <span class="kw1">class</span>=<span class="st0">&quot;bold&quot;</span>&gt;bold hello&lt;/p&gt;<br />
9
+ &nbsp; &lt;body&gt;<br />
10
+ &lt;/html&gt;<br />
11
+ eohtml</div>
12
+ </div>
13
+ <p>You may look through the tree like so:</p>
14
+ <div class="codesnip-container" >
15
+ <div class="codesnip" style="font-family: monospace;">doc.<span class="me1">html</span>.<span class="me1">body</span>.<span class="kw3">p</span><span class="br0">&#40;</span>'.<span class="me1">bold</span>'<span class="br0">&#41;</span>.<span class="me1">text</span> <span class="co1"># =&gt; 'bold hello' </span></div>
16
+ </div>
17
+ <p>The way this works is that method missing is implemented on every node in the document tree. That method missing method creates an xpath or css query by using the method name and method arguments. This means that a new search is executed for every method call. It's fun for playing around, but you definitely won't get the same performance as using one specific CSS search.</p>
18
+ <p>My favorite part is that method missing is actually in the <a href="http://github.com/tenderlove/nokogiri/tree/master/lib/nokogiri/decorators/slop.rb" onclick="javascript:urchinTracker ('/outbound/article/github.com');">slop decorator</a>. When you use the Nokogiri::Slop() method, it adds the decorator to a list that gets mixed in to every node instance at runtime using Module#extend. That lets me have sweet method missing action, without actually putting method missing in my Node class.</p>
19
+ <p>Here is a simplified example:</p>
20
+ <div class="codesnip-container" >
21
+ <div class="codesnip" style="font-family: monospace;"><span class="kw1">module</span> Decorator<br />
22
+ &nbsp; <span class="kw1">def</span> method_a<br />
23
+ &nbsp; &nbsp; <span class="st0">&quot;method a&quot;</span><br />
24
+ &nbsp; <span class="kw1">end</span></p>
25
+ <p>&nbsp; <span class="kw1">def</span> method_b<br />
26
+ &nbsp; &nbsp; <span class="st0">&quot;method b: #{super}&quot;</span><br />
27
+ &nbsp; <span class="kw1">end</span><br />
28
+ <span class="kw1">end</span></p>
29
+ <p><span class="kw1">class</span> Foo<br />
30
+ &nbsp; <span class="kw1">def</span> method_b<br />
31
+ &nbsp; &nbsp; <span class="st0">&quot;inside foo&quot;</span><br />
32
+ &nbsp; <span class="kw1">end</span><br />
33
+ <span class="kw1">end</span></p>
34
+ <p>foo = Foo.<span class="me1">new</span><br />
35
+ foo.<span class="me1">extend</span><span class="br0">&#40;</span>Decorator<span class="br0">&#41;</span></p>
36
+ <p><span class="kw3">puts</span> foo.<span class="me1">method_a</span> <span class="co1"># =&gt; 'method a'</span><br />
37
+ <span class="kw3">puts</span> foo.<span class="me1">method_b</span> <span class="co1"># =&gt; 'method b: inside foo'</span></p>
38
+ <p>foo2 = Foo.<span class="me1">new</span><br />
39
+ <span class="kw3">puts</span> foo2.<span class="me1">method_b</span> <span class="co1"># =&gt; 'inside foo'</span><br />
40
+ <span class="kw3">puts</span> foo2.<span class="me1">method_a</span> <span class="co1"># =&gt; NoMethodError </span></div>
41
+ </div>
42
+ <p>Module#extend is used to add functionality to the <strong>instance</strong> 'foo', but not 'foo2'. Both 'foo' and 'foo2' are instances of Foo, but using Module#extend, we can conditionally add functionality <strong>without monkey patching</strong> and keeping a clean separation of concerns. You can even reach previous functionality by calling super.</p>
43
+ <p>But wait! There's more! You can stack up these decorators as much as you want. For example:</p>
44
+ <div class="codesnip-container" >
45
+ <div class="codesnip" style="font-family: monospace;"><span class="kw1">module</span> AddAString<br />
46
+ &nbsp; <span class="kw1">def</span> method<br />
47
+ &nbsp; &nbsp; <span class="st0">&quot;Added a string: #{super}&quot;</span><br />
48
+ &nbsp; <span class="kw1">end</span><br />
49
+ <span class="kw1">end</span></p>
50
+ <p><span class="kw1">module</span> UpperCaseResults<br />
51
+ &nbsp; <span class="kw1">def</span> method<br />
52
+ &nbsp; &nbsp; <span class="kw1">super</span>.<span class="me1">upcase</span><br />
53
+ &nbsp; <span class="kw1">end</span><br />
54
+ <span class="kw1">end</span></p>
55
+ <p><span class="kw1">class</span> Foo<br />
56
+ &nbsp; <span class="kw1">def</span> method<br />
57
+ &nbsp; &nbsp; <span class="st0">&quot;foo&quot;</span><br />
58
+ &nbsp; <span class="kw1">end</span><br />
59
+ <span class="kw1">end</span></p>
60
+ <p>foo = Foo.<span class="me1">new</span><br />
61
+ foo.<span class="me1">extend</span><span class="br0">&#40;</span>AddAString<span class="br0">&#41;</span><br />
62
+ foo.<span class="me1">extend</span><span class="br0">&#40;</span>UpperCaseResults<span class="br0">&#41;</span></p>
63
+ <p><span class="kw3">puts</span> foo.<span class="me1">method</span> <span class="co1"># =&gt; 'ADDED A STRING: FOO' </span></div>
64
+ </div>
65
+ <p>Conditional functionality added to methods with no weird "alias method chain" involvement. Awesome!</p>
66
+ <p>I love ruby!</p>
@@ -0,0 +1,610 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/atom10full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
3
+ <title>TrotterCashion - Home</title>
4
+ <id>tag:trottercashion.com,2008:mephisto/</id>
5
+ <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
6
+
7
+ <link href="http://trottercashion.com/" rel="alternate" type="text/html" />
8
+ <updated>2008-12-13T17:48:58Z</updated>
9
+ <link rel="self" href="http://feeds.feedburner.com/trottercashion" type="application/atom+xml" /><entry xml:base="http://trottercashion.com/">
10
+ <author>
11
+ <name>trotter</name>
12
+ </author>
13
+ <id>tag:trottercashion.com,2008-12-13:53</id>
14
+ <published>2008-12-13T17:43:00Z</published>
15
+ <updated>2008-12-13T17:48:58Z</updated>
16
+ <category term="dataurls" />
17
+ <category term="javascript" />
18
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/483840026/data-urls-and-document-domain" rel="alternate" type="text/html" />
19
+ <title>Data Urls and document.domain</title>
20
+ <content type="html">
21
+ &lt;p&gt;Well this is a bummer. It turns out that all data urls share a common domain of ””. This is a problem in &lt;span class="caps"&gt;HTML5&lt;/span&gt;, because access to sqlite databases is based on the document.domain (This is true in safari at least). Therefore, all data urls will share a common sqlite db environment, meaning that a data url from Google,could look in the database created by a Yahoo data url, given that they were able to guess the name of the database. Since I see data urls as a better way to do offline web apps than google gears, this is a problem that pains me. Does anyone know if there is a solution?&lt;/p&gt;
22
+
23
+
24
+ &lt;p&gt;My main thought on how to fix this would be to require the domain for any data url that is a target of an link be set to the domain of the linker. The same would go for any data url that is loaded via a src=””, but this shouldn’t matter as all scripts use the document domain and not their own domain for security purposes. In cases where this is no linker, data urls get their domain set to an md5 hash of their data. Anyone see any problems with this solution?&lt;/p&gt;
25
+
26
+
27
+ &lt;p&gt;If you don’t know what data urls are, check out my &lt;a href="http://trottercashion.com/2008/12/12/data-urls-are-fun"&gt;previous post&lt;/a&gt;.&lt;/p&gt;
28
+ </content> <feedburner:origLink>http://trottercashion.com/2008/12/13/data-urls-and-document-domain</feedburner:origLink></entry>
29
+ <entry xml:base="http://trottercashion.com/">
30
+ <author>
31
+ <name>trotter</name>
32
+ </author>
33
+ <id>tag:trottercashion.com,2008-12-12:48</id>
34
+ <published>2008-12-12T13:03:00Z</published>
35
+ <updated>2008-12-12T13:04:13Z</updated>
36
+ <category term="dataurls" />
37
+ <category term="iphone" />
38
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/482664882/data-urls-are-fun" rel="alternate" type="text/html" />
39
+ <title>Data Urls Are Fun!</title>
40
+ <content type="html">
41
+ &lt;p&gt;Lately I’ve been playing with data urls in an effort to use them as an alternative way to build iPhone apps. W. Clawpaws wrote an interesting &lt;a href="http://blog.clawpaws.net/post/2007/07/16/Storing-iPhone-apps-locally-with-data-URLs"&gt;post&lt;/a&gt; on this a year ago, but it seems that not much has been done since. If it’s possible, I plan to have a simple library built by end of year that will allow you to write data url apps that connect to a central server when available. Basically, it’ll make the persistence and speed arguments for writing native apps null and void.&lt;/p&gt;
42
+
43
+
44
+ &lt;p&gt;Anyway, enough of what I plan to do and more about actual data urls. “Data urls”http://en.wikipedia.org/wiki/Data_URI_scheme allow you to store a single image, some javascript, or even an entire web page in a url. The browser will then render that information as if it were pulling it from a normal http:// url. So they will increase the initial payload of your web page, but result in faster interactions once the page is loaded.&lt;/p&gt;
45
+
46
+
47
+ &lt;p&gt;Data urls have a format of&lt;/p&gt;
48
+
49
+
50
+ &lt;pre&gt;data:[&amp;lt;MIME-type&amp;gt;][;charset="&amp;lt;encoding&amp;gt;"][;base64],&amp;lt;data&amp;gt;&lt;/pre&gt;
51
+
52
+ &lt;p&gt;So if you see something like data:text/html;base64,PGh0bWw+, you’re looking at a data url. To see one in action, click the link below and have a look at the url in your navigation bar.&lt;/p&gt;
53
+
54
+
55
+ &lt;p&gt;
56
+ &lt;a&gt;Data url in action!&lt;/a&gt;
57
+ &lt;/p&gt;
58
+
59
+ &lt;p&gt;Check back in the near future for progress on the iPhone idea. In the meantime, enjoy playing with data urls.&lt;/p&gt;
60
+ </content> <feedburner:origLink>http://trottercashion.com/2008/12/12/data-urls-are-fun</feedburner:origLink></entry>
61
+ <entry xml:base="http://trottercashion.com/">
62
+ <author>
63
+ <name>trotter</name>
64
+ </author>
65
+ <id>tag:trottercashion.com,2008-12-11:44</id>
66
+ <published>2008-12-11T14:48:00Z</published>
67
+ <updated>2008-12-11T14:49:22Z</updated>
68
+ <category term="iphone" />
69
+ <category term="rails" />
70
+ <category term="speaking" />
71
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/481739351/iphone-on-rails-the-presentation" rel="alternate" type="text/html" />
72
+ <title>iPhone on Rails: The Presentation</title>
73
+ <content type="html">
74
+ &lt;p&gt;Last night’s presentation went pretty well. I gave a fairly high level (except for the XCode part) overview of developing web and native apps for the iPhone. I hope to spruce this one up based on the questions asked during the talk last night and give it again some place else. Anyway, slides are below.&lt;/p&gt;
75
+
76
+
77
+ &lt;div&gt;&lt;a href="http://www.slideshare.net/trotter/iphonerails-presentation?type=powerpoint" title="iPhone on Rails"&gt;iPhone on Rails&lt;/a&gt;&amp;lt;object height="355" width="425"&gt;&amp;lt;param /&gt;&amp;lt;param /&gt;&amp;lt;param /&gt;&amp;lt;embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=iphonerails-1229006573528763-1&amp;amp;#38;stripped_title=iphonerails-presentation" height="355" width="425"&gt;&amp;lt;/embed&gt;&amp;lt;/object&gt;&lt;div&gt;View SlideShare &lt;a href="http://www.slideshare.net/trotter/iphonerails-presentation?type=powerpoint" title="View iPhone on Rails on SlideShare"&gt;presentation&lt;/a&gt; or &lt;a href="http://www.slideshare.net/upload?type=powerpoint"&gt;Upload&lt;/a&gt; your own. (tags: &lt;a href="http://slideshare.net/tag/rails"&gt;rails&lt;/a&gt; &lt;a href="http://slideshare.net/tag/iphone"&gt;iphone&lt;/a&gt;)&lt;/div&gt;&lt;/div&gt;
78
+ </content> <feedburner:origLink>http://trottercashion.com/2008/12/11/iphone-on-rails-the-presentation</feedburner:origLink></entry>
79
+ <entry xml:base="http://trottercashion.com/">
80
+ <author>
81
+ <name>trotter</name>
82
+ </author>
83
+ <id>tag:trottercashion.com,2008-12-10:43</id>
84
+ <published>2008-12-10T16:17:00Z</published>
85
+ <updated>2008-12-10T16:17:37Z</updated>
86
+ <category term="iphone" />
87
+ <category term="speaking" />
88
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/480717107/iphone-on-rails" rel="alternate" type="text/html" />
89
+ <title>iPhone on Rails</title>
90
+ <content type="html">
91
+ &lt;p&gt;I’m a little late to this party, but I’m speaking at &lt;a href="http://www.phillyonrails.org/events/3"&gt;philly.rb&lt;/a&gt; tonight. The talk is about making rails backed iPhone apps, both web and native. It should be a raucous good time, so come on over if you’re near Philly.&lt;/p&gt;
92
+
93
+
94
+ &lt;p&gt;As an aside, there’s a chance that this will be taped or that I’ll actually upload my slides for once. That said, if you miss the talk, you’re probably shit out of luck for my valuable knowledge.&lt;/p&gt;
95
+ </content> <feedburner:origLink>http://trottercashion.com/2008/12/10/iphone-on-rails</feedburner:origLink></entry>
96
+ <entry xml:base="http://trottercashion.com/">
97
+ <author>
98
+ <name>trotter</name>
99
+ </author>
100
+ <id>tag:trottercashion.com,2008-10-01:39</id>
101
+ <published>2008-10-01T23:17:00Z</published>
102
+ <updated>2008-10-01T23:39:57Z</updated>
103
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/408719167/iphone-resources" rel="alternate" type="text/html" />
104
+ <title>iPhone Resources</title>
105
+ <content type="html">
106
+ &lt;p&gt;I’m sure you’ve heard by now that the &lt;a href="http://www.tuaw.com/2008/10/01/iphone-nda-dropped/"&gt;iPhone &lt;span class="caps"&gt;NDA&lt;/span&gt; has been lifted&lt;/a&gt;. This is great news for those of us that pretend to be iPhone developers, because we’re going to start seeing a lot more resources at our fingertips.&lt;/p&gt;
107
+
108
+
109
+ &lt;p&gt;I’m going to start keeping a moderated page of &lt;a href="http://trottercashion.com/iphone-development"&gt;iPhone development resources&lt;/a&gt; including links to blog posts, books, and maybe even podcasts. If you see any blog posts (I’m sure there’ll be tons in the next few days). Let me know and I’ll add them to the list.&lt;/p&gt;
110
+ </content> <feedburner:origLink>http://trottercashion.com/2008/10/1/iphone-resources</feedburner:origLink></entry>
111
+ <entry xml:base="http://trottercashion.com/">
112
+ <author>
113
+ <name>trotter</name>
114
+ </author>
115
+ <id>tag:trottercashion.com,2008-10-01:38</id>
116
+ <published>2008-10-01T23:10:00Z</published>
117
+ <updated>2008-10-01T23:11:49Z</updated>
118
+ <category term="javascript" />
119
+ <category term="rspec" />
120
+ <category term="screw-unit" />
121
+ <category term="testing" />
122
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/408699804/mocking-screw-unit-part-deux" rel="alternate" type="text/html" />
123
+ <title>Mocking Screw-Unit Part Deux</title>
124
+ <content type="html">
125
+ &lt;p&gt;I &lt;a href="http://trottercashion.com/2008/8/8/mocking-screw-unit"&gt;wrote earlier&lt;/a&gt; about how &lt;a href="http://github.com/tobowers"&gt;Topper&lt;/a&gt; &lt;a href="http://blog.toppingdesign.com/2008/07/22/screw-unit-javascript-mocking/"&gt;mocked out the dom&lt;/a&gt; for screw-unit testing. Taking his lead, I started playing with screw-unit and adding some mocking and stubbing in the &lt;a href="http://rspec.info"&gt;rspec&lt;/a&gt; way. It’s not quite release worthy, but it’s on github now and I think it’s nearly usable. Basically, it lets you do things like this:&lt;/p&gt;
126
+
127
+
128
+ &lt;pre class="javascript"&gt;
129
+ user = {login: 'bob'};
130
+ Screw.Stub.stub(user, 'login').andReturn('nancy');
131
+ user.login; // =&amp;gt; 'nancy'
132
+ Screw.Stub.reset(); // Called automatically after each spec
133
+ user.login; // =&amp;gt; 'bob'
134
+
135
+ // Will throw a spec failure if user.email() is never called.
136
+ Screw.stub.shouldReceive(user, 'email');
137
+ &lt;/pre&gt;
138
+
139
+ &lt;p&gt;Obviously shouldReceive is not quite complete. It’s missing with(), numberOfTimes(), and other things. Still, it’s good enough that others can start iterating on the model I’ve laid down. As I said earlier, my &lt;a href="http://github.com/trotter/screw-unit/tree/master"&gt;fork of screw-unit&lt;/a&gt; is available on github now, so have a look and feel free to leave questions in the comments.&lt;/p&gt;
140
+ </content> <feedburner:origLink>http://trottercashion.com/2008/10/1/mocking-screw-unit-part-deux</feedburner:origLink></entry>
141
+ <entry xml:base="http://trottercashion.com/">
142
+ <author>
143
+ <name>trotter</name>
144
+ </author>
145
+ <id>tag:trottercashion.com,2008-09-27:33</id>
146
+ <published>2008-09-27T23:33:00Z</published>
147
+ <updated>2008-10-14T14:10:17Z</updated>
148
+ <category term="bugs" />
149
+ <category term="git" />
150
+ <category term="git-bisect" />
151
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/405022957/git-bisect-is-your-new-best-friend" rel="alternate" type="text/html" />
152
+ <title>git-bisect Is Your New Best Friend</title>
153
+ <content type="html">
154
+ &lt;p&gt;To anyone not using &lt;a href="http://en.wikipedia.org/wiki/Git_(software)"&gt;git&lt;/a&gt;, jump to the bottom of the post then come back up.&lt;/p&gt;
155
+
156
+
157
+ &lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I’ve got an even faster method at the bottom now. Skip down there if you already know the basics of git-bisect.&lt;/p&gt;
158
+
159
+
160
+ &lt;p&gt;Ok, now let’s move on to the cool shit, &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/git-bisect.html"&gt;git-bisect&lt;/a&gt;. Git-bisect helps you figure out exactly what code change broke a feature in your app, even when that code change was made months ago. It works by assisting you in a binary tree search through your commits, pausing at each one so that you can run a test and mark that commit as good or bad. This can remarkably decrease the amount of time you spend trying to figure out what is causing a new bug, because you quickly can find the exact code change that introduced it.&lt;/p&gt;
161
+
162
+
163
+ &lt;p&gt;To use git-bisect, you first need a good test to run. Though you &lt;em&gt;could&lt;/em&gt; do a manual test like loading a page in your browser and verifying that things look correct, you will be much happier if you write an &lt;strong&gt;automated test&lt;/strong&gt; that you can run for each commit. Since I usually live in Ruby land, I’m fairly partial to &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html"&gt;TestUnit&lt;/a&gt; and &lt;a href="http://rspec.info"&gt;rSpec&lt;/a&gt; for my automated tests. If you’re in iPhone land, I strongly recommend using &lt;a href="http://code.google.com/p/google-toolbox-for-mac/"&gt;google-toolbox-for-mac&lt;/a&gt;.&lt;/p&gt;
164
+
165
+
166
+ &lt;p&gt;With automated test in hand, you can kick off git-bisect with &lt;code&gt;git bisect start&lt;/code&gt;. You then mark your current commit as bad using &lt;code&gt;git bisect bad&lt;/code&gt;. You then checkout a known good commit using &lt;code&gt;git checkout commit_hash&lt;/code&gt;. Run your test and mark it as good when it passes using &lt;code&gt;git bisect good&lt;/code&gt;. At this point, git-bisect takes over and starts moving you through commit after commit. At each stop, you run your test and then mark the commit using either &lt;code&gt;git bisect bad&lt;/code&gt; or &lt;code&gt;git bisect good&lt;/code&gt;. At the end, git-bisect will tell you which commit first caused your error. You can then use &lt;code&gt;git diff commit_hash&lt;/code&gt; to see what was changed in that commit. When you’re done, you run &lt;code&gt;git bisect reset&lt;/code&gt; to set everything back to normal.&lt;/p&gt;
167
+
168
+
169
+ &lt;p&gt;A typical git-bisect session looks somewhat like this:&lt;/p&gt;
170
+
171
+
172
+ &lt;pre&gt;
173
+ (master) $ git bisect start
174
+
175
+ (master|BISECTING) $ git bisect bad
176
+
177
+ (master|BISECTING) $ git checkout eb5eecbb8fc4e2a964e8d2043d8b95f4eb7b563a
178
+ HEAD is now at eb5eecb... Add MainViewController
179
+
180
+ ... run test which passes ...
181
+
182
+ (eb5eecb...|BISECTING) $ git bisect good
183
+ Bisecting: 3 revisions left to test after this
184
+ [d82c1595b6363484fe0d7f60f9ffa096d777bf17] First CompsView test
185
+
186
+ ... run test which fails ...
187
+
188
+ (d82c159...|BISECTING) $ git bisect bad
189
+ Bisecting: 1 revisions left to test after this
190
+ [93af33167019fa039f5372dff602a76cbcbc99bb] Add first integration test
191
+
192
+ ... run test which passes ...
193
+
194
+ (93af331...|BISECTING) $ git bisect good
195
+ Bisecting: 0 revisions left to test after this
196
+ [4f12091a287c363737ceb650df46196e5008d3f2] Add Comps target
197
+
198
+ ... run test which fails ...
199
+
200
+ (4f12091...|BISECTING) $ git bisect bad
201
+ 4f12091a287c363737ceb650df46196e5008d3f2 is first bad commit
202
+ commit 4f12091a287c363737ceb650df46196e5008d3f2
203
+ Author: Trotter Cashion &amp;lt;cashion@example.com&amp;gt;
204
+ Date: Tue Sep 23 20:18:09 2008 -0400
205
+
206
+ Add Comps target
207
+
208
+ :000000 100644 0000000000000000000000000000000000000000 789bf7877c6059a7f3ac8cb2b53fdb2c903e58ff A Comps-Info.plist
209
+ :040000 040000 d260571a48328d4a575a7395cd6ece3d651a93ac a622a23fdb80c915eaba49d1d53f7bf0dbf44a70 M ShootAndSpeak.xcodeproj
210
+
211
+ ... Figure out what's wrong ...
212
+
213
+ (4f12091...|BISECTING) $ git bisect reset
214
+ Switched to branch "master"
215
+
216
+ &lt;/pre&gt;
217
+
218
+ &lt;p&gt;I hope you learn to use and love git-bisect. It’s really helped me when trying to find the cause of nasty bugs that seemingly came out of nowhere.&lt;/p&gt;
219
+
220
+
221
+ &lt;h3&gt;Update&lt;/h3&gt;
222
+
223
+
224
+ &lt;p&gt;The above is too much work. While searching the &lt;a href="http://desprofundis.blogspot.com/2008/06/git-bisect-instructions.html"&gt;net&lt;/a&gt;, I found something even easier and faster. You can start git-bisect with the commit hashes like so &lt;code&gt;git bisect start bad_commit good_commit&lt;/code&gt;. Even better, you can then tell git-bisect to run the tests itself… this is where things get awesome: &lt;code&gt;git bisect run some_test&lt;/code&gt;. It’ll iterate through your commits until it finds the bad one. Checkout the sample session below.&lt;/p&gt;
225
+
226
+
227
+ &lt;pre&gt;
228
+ /tmp/fake(master) $ git bisect start 68d5ab7a61a871fd097d8820e248cfd168395e4e 20cbc038973d6c78805bc8bfc3d187c2b537f183
229
+ Bisecting: 1 revisions left to test after this
230
+ [3da37ed0ee87c9129a61142ecefef17ab0de7f0f] Test works
231
+
232
+ /tmp/fake(3da37ed...|BISECTING) $ git bisect run testrb test/unit/some_test.rb -n test_truth
233
+ running testrb test/unit/some_test.rb -n test_truth
234
+ Loaded suite some_test.rb
235
+ Started
236
+ .
237
+ Finished in 0.000338 seconds.
238
+
239
+ 1 tests, 1 assertions, 0 failures, 0 errors
240
+ Bisecting: 0 revisions left to test after this
241
+ [765d7e5c4eba730078907fc00121b8b35ada64b0] Test fails
242
+ running testrb test/unit/some_test.rb -n test_truth
243
+ Loaded suite some_test.rb
244
+ Started
245
+ F
246
+ Finished in 0.009607 seconds.
247
+
248
+ 1) Failure:
249
+ test_truth(ThisTest) [./test/unit/some_test.rb:5]:
250
+ &amp;lt;false&amp;gt; is not true.
251
+
252
+ 1 tests, 1 assertions, 1 failures, 0 errors
253
+ 765d7e5c4eba730078907fc00121b8b35ada64b0 is first bad commit
254
+ commit 765d7e5c4eba730078907fc00121b8b35ada64b0
255
+ Author: Trotter Cashion &amp;lt;cashion@example.com&amp;gt;
256
+ Date: Sun Sep 28 13:13:09 2008 -0400
257
+
258
+ Test fails
259
+
260
+ :040000 040000 167dd04f2b4101ea256a7a6525859bc03e5433d3 0b062d4b5b03e7ac51ac4050fc7397c8983a2f13 M test
261
+ bisect run success
262
+
263
+ /tmp/fake(765d7e5...|BISECTING) $
264
+
265
+ &lt;/pre&gt;
266
+
267
+ &lt;p&gt;As you can see above, I’m using ruby for this set of tests. My preferred method is to have git-bisect run testrb (or spec) and specify a single test for it to execute. This ensures that everything runs quite quickly.&lt;/p&gt;
268
+
269
+
270
+ &lt;h3&gt;Land Here!&lt;/h3&gt;
271
+
272
+
273
+ &lt;p&gt;If you jumped here from the top, I regret to inform you that this post will make you very sad. Turn back now before you’re stuck improving your life by &lt;a href="http://git.or.cz/#download"&gt;installing git&lt;/a&gt;. Once you’ve installed git, go check out &lt;a href="http://peepcode.com/"&gt;Peepcode&lt;/a&gt;. They’ve got a really good &lt;a href="https://peepcode.com/products/git"&gt;screencast&lt;/a&gt; and &lt;a href="https://peepcode.com/products/git-internals-pdf"&gt;pdf&lt;/a&gt; that explain git excellently.&lt;/p&gt;
274
+ </content> <feedburner:origLink>http://trottercashion.com/2008/9/27/git-bisect-is-your-new-best-friend</feedburner:origLink></entry>
275
+ <entry xml:base="http://trottercashion.com/">
276
+ <author>
277
+ <name>trotter</name>
278
+ </author>
279
+ <id>tag:trottercashion.com,2008-08-08:31</id>
280
+ <published>2008-08-08T11:35:00Z</published>
281
+ <updated>2008-08-08T11:36:11Z</updated>
282
+ <category term="javascript" />
283
+ <category term="mocks" />
284
+ <category term="screw-unit" />
285
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/359351596/mocking-screw-unit" rel="alternate" type="text/html" />
286
+ <title>Mocking Screw-Unit</title>
287
+ <content type="html">
288
+ &lt;p&gt;I’m big on tests. Unit testing helps me clarify my thinking on problems and ensure that my code works well. When writing tests, it’s essential to have a good mocking framework to separate the things you are testing from the things you are not. In Ruby, I like using flexmock for Test::Unit and rSpec’s built in mocking framework when using it. In Javascript though, screw-unit doesn’t really come with a way to mock by default. (As an aside, screw-unit totally rocks for testing js.)&lt;/p&gt;
289
+
290
+
291
+ &lt;p&gt;Thankfully, my coworker &lt;a href="http://github.com/tobowers"&gt;Topper&lt;/a&gt; (who’s a kickass dev, btw), has been playing around with adding mocking to screw-unit. He’s got a &lt;a href="http://github.com/tobowers/screw-unit/tree/master"&gt;fork&lt;/a&gt; on github, docs at the previous link, and a quick &lt;a href="http://blog.toppingdesign.com/2008/07/22/screw-unit-javascript-mocking/"&gt;example blog post&lt;/a&gt;. Click through and check this shit out, cause it’s hot.&lt;/p&gt;
292
+ </content> <feedburner:origLink>http://trottercashion.com/2008/8/8/mocking-screw-unit</feedburner:origLink></entry>
293
+ <entry xml:base="http://trottercashion.com/">
294
+ <author>
295
+ <name>trotter</name>
296
+ </author>
297
+ <id>tag:trottercashion.com,2008-07-07:27</id>
298
+ <published>2008-07-07T17:19:00Z</published>
299
+ <updated>2008-07-07T17:21:30Z</updated>
300
+ <category term="floats" />
301
+ <category term="ruby" />
302
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/329041849/floating-pain" rel="alternate" type="text/html" />
303
+ <title>Floating Pain</title>
304
+ <content type="html">
305
+ &lt;p&gt;&lt;a href="http://blog.toppingdesign.com/"&gt;Topper&lt;/a&gt; mentioned a tweet he saw to me in which someone asked why &lt;code&gt;(4.6 * 100).to_i #=&amp;gt; 459&lt;/code&gt;. Though this seems like a ruby bug, it’s really just one of the annoying things you hit with rounding errors and floats. At issue is that &lt;code&gt;#to_i&lt;/code&gt; floors the float, instead of rounding it. Since the value may be approximated at 459.999999, the &lt;code&gt;#to_i&lt;/code&gt; floors it to 459. To have things work like you’d expect, use &lt;code&gt;#round&lt;/code&gt; when converting &lt;code&gt;Float&lt;/code&gt; to &lt;code&gt;Fixnum&lt;/code&gt;. See below for some code examples:&lt;/p&gt;
306
+
307
+
308
+ &lt;pre class="ruby"&gt;
309
+ 4.6.to_i # =&amp;gt; 4
310
+ 4.6.round # =&amp;gt; 5
311
+ (4.6 * 100).to_i # =&amp;gt; 459
312
+ (4.6 * 100).round # =&amp;gt; 460
313
+ &lt;/pre&gt;
314
+ </content> <feedburner:origLink>http://trottercashion.com/2008/7/7/floating-pain</feedburner:origLink></entry>
315
+ <entry xml:base="http://trottercashion.com/">
316
+ <author>
317
+ <name>trotter</name>
318
+ </author>
319
+ <id>tag:trottercashion.com,2008-06-27:26</id>
320
+ <published>2008-06-27T03:06:00Z</published>
321
+ <updated>2008-06-27T03:07:05Z</updated>
322
+ <category term="programming" />
323
+ <category term="trotter cashion" />
324
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/321023468/how-i-got-started-programming" rel="alternate" type="text/html" />
325
+ <title>How I Got Started Programming</title>
326
+ <content type="html">
327
+ &lt;p&gt;&lt;a href="http://www.pauldix.net/2008/06/how-i-got-start.html"&gt;Paul&lt;/a&gt; says I’ve got to do this, and I don’t want to let him
328
+ down. &lt;a href="http://gilesbowkett.blogspot.com/2008/06/how-i-got-started-programming.html"&gt;Giles&lt;/a&gt; tagged him first, so you should probably read his too.&lt;/p&gt;
329
+
330
+
331
+ &lt;h3&gt;How old were you when you started programming?&lt;/h3&gt;
332
+
333
+
334
+ &lt;p&gt;In third grade (when I was 8) I started started taking super nerd math classes
335
+ with other super nerds. As part of those classes, they had us programming a
336
+ turtle to draw things on the screen. &lt;a href="http://en.wikipedia.org/wiki/Logo_(programming_language"&gt;Logo&lt;/a&gt;) was totally awesome and had me hooked
337
+ on the magic of programming.&lt;/p&gt;
338
+
339
+
340
+ &lt;h3&gt;How did you get started programming?&lt;/h3&gt;
341
+
342
+
343
+ &lt;p&gt;After Logo, my dad (he was a &lt;span class="caps"&gt;CTO&lt;/span&gt; at the time) bought me Visual Studio and a few
344
+ books on Visual Basic. It was lots of “Teach Yourself X in X days”, and I ran
345
+ through VB, C++, and a little Delphi. Naturally, those books didn’t teach me to
346
+ actually be good, though I did figure out how to make a few small games that I
347
+ could play.&lt;/p&gt;
348
+
349
+
350
+ &lt;p&gt;My dad was a &lt;span class="caps"&gt;CTO&lt;/span&gt; at an investment bank, which is the kind of place that treats a
351
+ &lt;span class="caps"&gt;CTO&lt;/span&gt; like crap. I didn’t want to be the guy that got shat on, so in high school I
352
+ dropped programming and started learning businessy things. I even picked my
353
+ college based on the strength of its business school. Once I showed up, I
354
+ realized that I didn’t like anyone at the business school, that philosophy was
355
+ fun, and that math/econ could make me money. I promptly switched my major.&lt;/p&gt;
356
+
357
+
358
+ &lt;p&gt;After college, I went to work at a job that I ended up hating, quit it, took a
359
+ few months to figure out my life, and realized that I really loved programming.
360
+ Thankfully I got lucky and read a &lt;a href="http://lifehacker.com/software/notag/ruby-on-rails-book-as-a-download-105594.php"&gt;blog post&lt;/a&gt; that tipped me to
361
+ the beta book of &lt;span class="caps"&gt;AWDWR&lt;/span&gt;, which taught me a lot about &lt;strong&gt;real&lt;/strong&gt; programming. I
362
+ consider that the start of me becomming a real programmer, and not just some kid
363
+ that can code.&lt;/p&gt;
364
+
365
+
366
+ &lt;h3&gt;What was your first language?&lt;/h3&gt;
367
+
368
+
369
+ &lt;p&gt;Logo! Drawing with turtles rocks so hard. After that it was VB, which let me
370
+ push Windows around and made me a little cash.&lt;/p&gt;
371
+
372
+
373
+ &lt;h3&gt;What was the first real program you wrote?&lt;/h3&gt;
374
+
375
+
376
+ &lt;p&gt;I wrote my first useful program while working as an intern at a financial
377
+ services firm. The company was using &lt;a href="http://www.advent.com/solutions/asset_managers/axys_platform"&gt;Axys&lt;/a&gt; (really bad website alert!) for portfolio analysis and had a
378
+ tedious process for reconciling their branches with the back office. I wrote a
379
+ VB program that helped them to perform these reconciliations more quickly, which
380
+ I hear they still use.&lt;/p&gt;
381
+
382
+
383
+ &lt;h3&gt;What languages have you used since you started programming?&lt;/h3&gt;
384
+
385
+
386
+ &lt;p&gt;Logo, VB, C, C++, Delphi, Ruby, Objective-C, Erlang, Scheme, Javascript, Java, and maybe something else. Of those, I’d feel comfortable working on a project using Ruby, Javascript, Objective-C, or Erlang. I’m skilled enough in some of the others, but have vowed to never use them again. I’ll let you guess which.&lt;/p&gt;
387
+
388
+
389
+ &lt;h3&gt;What was your first professional programming gig?&lt;/h3&gt;
390
+
391
+
392
+ &lt;p&gt;2005 at the Nathan Kline Institute for Mental Health. There was a PhD there who
393
+ needed &lt;a href="http://en.wikipedia.org/wiki/ImageJ"&gt;ImageJ&lt;/a&gt; to talk to his microscope over a serial port and to have a
394
+ lot of old scripts from ObjectImage translated into ImageJ. It was a fun job
395
+ that let me work at my own pace and play a lot with the art of programming.&lt;/p&gt;
396
+
397
+
398
+ &lt;h3&gt;If there is one thing you learned along the way that you would tell new
399
+ developers, what would it be?&lt;/h3&gt;
400
+
401
+
402
+ &lt;p&gt;Surround yourself with great people, and never be the smartest guy in the room. If you’re lucky enough to work at a
403
+ company with some great programmers, you’ll learn a whole lot that way. If
404
+ your company is full of 9-5 coders, join a local developer group or start your
405
+ own. &lt;a href="http://nycruby.org"&gt;Nyc.rb&lt;/a&gt; and &lt;a href="http://www.phillyonrails.org/"&gt;Philly On Rails&lt;/a&gt; totally rock, so you could always move to New York or Philly and learn from some of the best.&lt;/p&gt;
406
+
407
+
408
+ &lt;h3&gt;What’s the most fun you’ve ever had programming?&lt;/h3&gt;
409
+
410
+
411
+ &lt;p&gt;Logo. I used to love making that little turtle draw all sorts of fun things on
412
+ the screen. There was no real need to make the turtle do things, I was doing it
413
+ just for the joy of it. I managed to recreate some of that feeling when working
414
+ on &lt;a href="http://rubyforge.org/projects/spec-unit/"&gt;spec-unit&lt;/a&gt;, which is really my only useful open source contribution to
415
+ date. Unfortunately, it only has one release ever, and I haven’t messed with it in two years.&lt;/p&gt;
416
+ </content> <feedburner:origLink>http://trottercashion.com/2008/6/27/how-i-got-started-programming</feedburner:origLink></entry>
417
+ <entry xml:base="http://trottercashion.com/">
418
+ <author>
419
+ <name>trotter</name>
420
+ </author>
421
+ <id>tag:trottercashion.com,2008-06-22:5</id>
422
+ <published>2008-06-22T22:23:00Z</published>
423
+ <updated>2008-06-22T22:44:05Z</updated>
424
+ <category term="business" />
425
+ <category term="working remotely" />
426
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/317690654/on-working-remotely" rel="alternate" type="text/html" />
427
+ <title>On Working Remotely</title>
428
+ <content type="html">
429
+ &lt;p&gt;Being on my honeymoon in St. Barths has got me thinking a bit about working remotely. Don’t worry, I’m not working on this trip. I’m more trying to think if ways I could stay on this trip indefinitely, but still manage to make some cash.&lt;/p&gt;
430
+
431
+
432
+ &lt;p&gt;I’m no stranger to remote work. As some of you may know, I live in Philly but continue to work for &lt;a href="http://www.motionbox.com"&gt;Motionbox&lt;/a&gt; in New York. I commute two days per week, and spend the rest working from home in Philly. Over the past year, I’ve started to catalog my likes and dislikes with this arrangement, and I’m going to list some of my dislikes here along with some possible ways to improve things. For now, we’ll just look at the first problem I’ve encountered:&lt;/p&gt;
433
+
434
+
435
+ &lt;h3&gt;You’re out of touch&lt;/h3&gt;
436
+
437
+
438
+ &lt;p&gt;If you’re distributed while the rest of the team is collocated, you &lt;strong&gt;will&lt;/strong&gt; be out of the loop. When your boss is walking around the office and stopping at various desks, he won’t be stopping at yours. If you’re looking to be recognized for your accomplishments, this can be a major problem. It’s difficult to advance in the company if you’re not visible.&lt;/p&gt;
439
+
440
+
441
+ &lt;p&gt;To combat this problem, I’ve found getting everyone on IM and &lt;span class="caps"&gt;IRC&lt;/span&gt; to be very helpful. If your company uses an open office, you’re in luck. The noise from the floor plan typically causes people to use headphones, so they’ll be much more prone to use IM and &lt;span class="caps"&gt;IRC&lt;/span&gt; for all their communication (even with those people right next to them). Another good technique is to send copious amounts of email. If people are cataloging what should be done and who has done what through email (a good practice regardless), then it’s much easier for you to keep track of what is happening in the office.&lt;/p&gt;
442
+
443
+
444
+ &lt;p&gt;I don’t think that Skype or frequent phone calls help much in this regard. Typically, you’re only talking to one person and all the speaker phone arrangements I’ve seen aren’t that great. Voice is great for quickly hashing out the details of a plan with one other person, but is terrible as a mechanism for keeping up with the goings on of the company.&lt;/p&gt;
445
+
446
+
447
+ &lt;p&gt;Making time (and spending the money) to get to the office at least once a month is invaluable. Though email, IM, and &lt;span class="caps"&gt;IRC&lt;/span&gt; help, they’re not a real substitute for quality time in person. One of the most important things I’ve done at Motionbox is to know when people are going out for after work drinks to celebrate various accomplishments and made sure that I was able to be in town for them. Though it sounds silly to talk about drinking as an important part of work, the main thing you miss by being remote is the social component. It’s much more important to get in town to socialize than it is to do actual work. You’ll have plenty of time to work when you’re home alone the next day.&lt;/p&gt;
448
+
449
+
450
+ &lt;p&gt;Anyone have any thoughts on other ways to keep in touch while working remotely?&lt;/p&gt;
451
+ </content> <feedburner:origLink>http://trottercashion.com/2008/6/22/on-working-remotely</feedburner:origLink></entry>
452
+ <entry xml:base="http://trottercashion.com/">
453
+ <author>
454
+ <name>trotter</name>
455
+ </author>
456
+ <id>tag:trottercashion.com,2008-06-11:20</id>
457
+ <published>2008-06-11T02:30:00Z</published>
458
+ <updated>2008-06-11T02:46:16Z</updated>
459
+ <category term="belongstodemeter" />
460
+ <category term="rails" />
461
+ <category term="ruby" />
462
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/309293334/belongstodemeter" rel="alternate" type="text/html" />
463
+ <title>BelongsToDemeter</title>
464
+ <content type="html">
465
+ &lt;p&gt;While playing with Rails the other day, I thought it would be fun if you could get at attributes of a belongs_to association without having to do the whole traverse association and check for nil thing.&lt;/p&gt;
466
+
467
+ &lt;pre class="ruby"&gt;
468
+
469
+ # Something like...
470
+ @person.group_name # =&gt; "Pizza Fans!" || nil
471
+
472
+ # Instead of...
473
+ @person.group ? @person.group.name : nil # =&gt; "Pizza Fans!" || nil
474
+
475
+ &lt;/pre&gt;
476
+
477
+ &lt;p&gt;Thinking this would be a fun chance to play with some meta, I threw together &lt;a href="http://github.com/trotter/belongs_to_demeter/tree/master"&gt;BelongsToDemeter&lt;/a&gt;, which you can find over on &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt;. It's a rails plugin, but don't expect it to actually install using script/plugin. The code is complete and utter crap, so it's probably best that Rails won't install it. It is slow, and most likely prone to error. Still, it's a fun little thought experiment, and I may decide to clean it up then speed it up if someone tells me they like it.&lt;/p&gt;
478
+
479
+ &lt;p&gt;It does what I explained above and also lets you do fun things like this, which I think are useful when assigning associations through a form:&lt;/p&gt;
480
+
481
+ &lt;pre class="ruby"&gt;
482
+
483
+ # Lookup the user 'Bob' by login and assign
484
+ # it to the user association
485
+ @character.user # =&gt; nil
486
+ @character.user_login = "bob"
487
+ @character.user.login # =&gt; "bob"
488
+
489
+ &lt;/pre&gt;
490
+
491
+ &lt;p&gt;Anyway, go over to &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt; and check out &lt;a href="http://github.com/trotter/belongs_to_demeter/tree/master"&gt;BelongsToDemeter&lt;/a&gt;. When you're done, let me know if you like the concept. After all that, go erase all memory of the implementation details from your mind, they're ugly.&lt;/p&gt;
492
+ </content> <feedburner:origLink>http://trottercashion.com/2008/6/11/belongstodemeter</feedburner:origLink></entry>
493
+ <entry xml:base="http://trottercashion.com/">
494
+ <author>
495
+ <name>trotter</name>
496
+ </author>
497
+ <id>tag:trottercashion.com,2008-06-05:16</id>
498
+ <published>2008-06-05T02:22:00Z</published>
499
+ <updated>2008-06-11T02:48:00Z</updated>
500
+ <category term="macro tests" />
501
+ <category term="rspec" />
502
+ <category term="ruby" />
503
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/304990208/macro-tests" rel="alternate" type="text/html" />
504
+ <title>Macro Tests</title>
505
+ <content type="html">
506
+ &lt;p&gt;I went to &lt;a href="http://blog.hasmanythrough.com/"&gt;Josh Susser&lt;/a&gt;'s talk at RailsConf last week, where he mentioned that no one really writes macro tests with rSpec. Naturally, I found this to be a true shame, since I think macro tests are a great way to clean up your code. What's a macro test you ask? Sit right there and I'll tell you.&lt;/p&gt;
507
+
508
+ &lt;p&gt;A macro test is a test that defines other tests for you. It's a great way to reduce repetition in your test code, thereby making it easier to read. Take these three tests as an example:&lt;p&gt;
509
+
510
+ &lt;pre class="ruby"&gt;
511
+ describe 'GET /users/:user_id/posts/:post_id/comments' do
512
+ it 'should be a success' do
513
+ get :index, :user_id =&amp;gt; 2, :post_id =&amp;gt; 3
514
+ response.should be_success
515
+ end
516
+
517
+ it 'should 404 without a user id' do
518
+ get :index, :post_id =&amp;gt; 3
519
+ response.headers['Status'].to_i.should == 404
520
+ end
521
+
522
+ it 'should 404 without a post id' do
523
+ get :index, :user_id =&amp;gt; 2
524
+ response.headers['Status'].to_i.should == 404
525
+ end
526
+ end
527
+ &lt;/pre&gt;
528
+
529
+ &lt;p&gt;Obviously there's a little bit of duplication in the 404's. Let's define macro tests to clean that up.&lt;/p&gt;
530
+
531
+ &lt;pre class="ruby"&gt;
532
+ describe 'GET /users/:user_id/posts/:post_id/comments' do
533
+ def self.should_404_without(param)
534
+ # Since you're calling this method within the describe block,
535
+ # it is being called within the correct context.
536
+ it "should 404 without #{param}" do
537
+ get :index, paramz.merge(param.to_sym =&amp;gt; nil)
538
+ response.headers['Status'].to_i.should == 404
539
+ end
540
+ end
541
+
542
+ should_404_without "user_id"
543
+ should_404_without "post_id"
544
+
545
+ # Normally I put this at the bottom, only here to keep it close to the above.
546
+ # This method is called by the test the macro test defines to hand off the params.
547
+ def paramz
548
+ {:user_id =&amp;gt; 2, :post_id =&amp;gt; 3}
549
+ end
550
+
551
+ it 'should be a success' do
552
+ get :index, paramz
553
+ response.should be_success
554
+ end
555
+ end
556
+ &lt;/pre&gt;
557
+
558
+ &lt;p&gt;Hmm... this doesn't really look any cleaner. The problem is that we did this for only one action. If we generalize should_404_without more, then we can put it into its own shared example set that we can include in any describe block. Let's look at that now.&lt;/p&gt;
559
+
560
+ &lt;pre class="ruby"&gt;
561
+ shared_examples_for "controllers" do
562
+ def self.should_normally_succeed
563
+ it 'should be a success' do
564
+ get @action, paramz
565
+ response.should be_success
566
+ end
567
+ end
568
+
569
+ def self.should_404_without(param)
570
+ it "should 404 without #{param}" do
571
+ get @action, paramz.merge(param.to_sym =&amp;gt; nil)
572
+ response.headers['Status'].to_i.should == 404
573
+ end
574
+ end
575
+ end
576
+
577
+ describe 'GET /users/:user_id/posts/:post_id/comments' do
578
+ it_should_behave_like "controllers"
579
+
580
+ before(:each) { @action = :index }
581
+
582
+ should_normally_succeed
583
+ should_404_without "user_id"
584
+ should_404_without "post_id"
585
+
586
+ def paramz
587
+ {:user_id =&amp;gt; 2, :post_id =&amp;gt; 3}
588
+ end
589
+ end
590
+ &lt;/pre&gt;
591
+
592
+ &lt;p&gt;Oh snap! That describe block is a lot cleaner, and we can tuck the shared examples into spec_helper.rb to really clean things up. Using macro tests, you'll find it's very easy to create a lot of REST controllers very quickly. In fact, I plan on open sourcing something to help with that very soon...&lt;/p&gt;
593
+
594
+ &lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: See the comments for David's advice on pulling this out of shared examples and into a module that you can then add to rSpec. This cleans up the describe blocks even more. Mega win!&lt;/p&gt;
595
+ </content> <feedburner:origLink>http://trottercashion.com/2008/6/5/macro-tests</feedburner:origLink></entry>
596
+ <entry xml:base="http://trottercashion.com/">
597
+ <author>
598
+ <name>trotter</name>
599
+ </author>
600
+ <id>tag:trottercashion.com,2008-05-04:12</id>
601
+ <published>2008-05-04T04:14:00Z</published>
602
+ <updated>2008-05-04T14:39:31Z</updated>
603
+ <category term="moving" />
604
+ <category term="starting" />
605
+ <link href="http://feeds.feedburner.com/~r/trottercashion/~3/283393385/starting-the-car" rel="alternate" type="text/html" />
606
+ <title>Starting the Car</title>
607
+ <content type="html">
608
+ &lt;p&gt;Well, it's not much of a start, but every trip must have a beginning. As I wake up and wipe my bleary eyes, I'm going to slowly pull this car out of the driveway and put it on the road. The tunes aren't yet cranking; no Allman Brothers is yet helping us greet the open road. Still, we've left that old home that is &lt;a href="http://lifecoding.com"&gt;lifecoding&lt;/a&gt; and are starting out on something new, something fresh. We're running on rubies with a comfortable walking shoe pushing the accelerator. I hope you enjoy this ride.&lt;/p&gt;
609
+ </content> <feedburner:origLink>http://trottercashion.com/2008/5/4/starting-the-car</feedburner:origLink></entry>
610
+ </feed>