Skip to content

Instantly share code, notes, and snippets.

@joefiorini
Created May 15, 2011 17:41
Show Gist options
  • Save joefiorini/973355 to your computer and use it in GitHub Desktop.
Save joefiorini/973355 to your computer and use it in GitHub Desktop.
decent_exposure and Rails-less testing
require 'units/spec_helper'
require 'reviews_controller'
class Review; end
describe ReviewsController do
let(:controller) { ReviewsController.new }
it { should expose :reviews }
it { should expose :review }
it "loads all reviews" do
reviews = stub
Review.stub_chain(:all, :entries).and_return(reviews)
controller.reviews.should == reviews
end
end
RSpec::Matchers.define :expose do |expected|
match do |actual|
actual.class._exposed.include? expected
end
failure_message_for_should do |actual|
"expected %p to expose a method named %p" % [actual, expected]
end
description do
"expose the method %p" % expected
end
end
module DecentStubs
def _exposed
@exposed ||= []
@exposed
end
def expose(attr, &block)
_exposed << attr
if block
define_method attr, &block
else
attr_reader attr
end
end
end
class ApplicationController
extend DecentStubs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment