Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Degraderator

  • Loading branch information...
commit 8e1495dacc1607283f652d679573c12da8d2eeda 1 parent 3033493
Jake Douglas jakedouglas authored
10 lib/degraderator.rb
View
@@ -0,0 +1,10 @@
+class Degraderator
+ def initialize(degrade, object)
+ @degrade = degrade
+ @object = object
+ end
+
+ def method_missing(method, *args)
+ @degrade.perform { @object.send(method, *args) }
+ end
+end
26 spec/degraderator_spec.rb
View
@@ -0,0 +1,26 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Degraderator do
+ before do
+ @degrade = stub("Degrade")
+ # it seems that mocha doesn't let you pass a block that gets
+ # the arguments passed to it, and has the result returned. erg.
+ @degrade.stubs(:perform).yields.returns(:bar)
+
+ @object = stub("Something", :foo => :bar)
+ @degraderator = Degraderator.new(@degrade, @object)
+ @result = @degraderator.foo("boom")
+ end
+
+ it "calls perform" do
+ @degrade.should have_received(:perform)
+ end
+
+ it "uses method_missing to delegate method calls to the object" do
+ @object.should have_received(:foo).with("boom")
+ end
+
+ it "returns the result from the object" do
+ @result.should == :bar
+ end
+end
1  spec/spec_helper.rb
View
@@ -1,6 +1,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'degrade'
+require 'degraderator'
require 'spec'
require 'spec/autorun'
require 'bourne'
Please sign in to comment.
Something went wrong with that request. Please try again.