Created
May 15, 2011 17:41
-
-
Save joefiorini/973355 to your computer and use it in GitHub Desktop.
decent_exposure and Rails-less testing
This file contains 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
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 |
This file contains 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
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 | |
This file contains 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 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