This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# caching constraint | |
module Blog | |
Routes = Raptor.routes(Blog) do | |
show :to => 'Post.find', :unless :post_cached | |
show :responder => NoContentResponder | |
end | |
class PostCached | |
def match?(id, cache_control) | |
post = Post.find(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Blog | |
Routes = Raptor.routes(Blog) do | |
show :to => 'Post.find', :http_cache_requirement => :post_cached | |
end | |
class PostCached | |
def match?(id, cache_control) | |
post = Post.find(id) | |
post.updated_at =< cache_control | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Blog | |
Routes = Raptor.routes(Blog) do | |
show :to => 'Post.find', :if => :post_not_cached | |
end | |
class PostNotCached | |
def match?(id, cache_control) | |
post = Post.find(id) | |
post.updated_at =< cache_control | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(unfinished bar) | |
(defn foo [stuff incoming] | |
(first | |
(filter | |
(fn [a-thing] | |
(bar a-thing incoming)) | |
stuff))) | |
;; this actually calls bar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
def an(value) | |
Thingy.new(value) | |
end | |
def none | |
Nothing.new | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# with dependency injection, and slightly different route syntax: | |
module WebCrawler | |
Routes = Raptor::App.new(self) do | |
queue = #... some sort of persistent queue initialized here | |
crawler = WebCrawler.new(queue) | |
path "to-be-crawled" do | |
create crawler, :enqueue!, :require => :logged_in | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Note, the "don't stub external APIs" is a rule, but like all design/testing rules it *should* be broken with good judgement. Furthermore, like all design/testing rules, the best way to learn when to break it is to follow it rigorously until it leads you to a bad place. | |
Problems | |
-------- | |
- Stubbing external APIs gives you no design feedback: you cannot change the third party API (unless you monkey patch, but seriously, Fuck That Shit. Since stubbing/mocking are primarily a design tool (for me), having to stub/mock something I cannot/will not change seems pointless. | |
- Stubbing a third party API relies on you having intimate understanding of the docs, including error conditions, timeouts etc. I'm not confident in my ability to successfully stub a third party API on each conditions. | |
The Solution | |
------------ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.3p125 :001 > class Foo < RuntimeError; def to_str; "other_string"; end; end | |
=> nil | |
1.9.3p125 :002 > begin raise Foo.new; rescue Foo => e; end | |
RuntimeError: other_string | |
from (irb):2 | |
from /Users/tcrayford/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
specify "the first time rspec has made me sad" do | |
class CustomError < RuntimeError; end | |
expect do | |
raise CustomError.new('what') | |
end.to raise(CustomError.new('what')) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
specify "the first time rspec has made me sad" do | |
class CustomError < RuntimeError; end | |
expect do | |
raise CustomError.new('what') | |
end.to raise_error(CustomError.new('what')) | |
end |