Created
October 17, 2008 20:07
-
-
Save Peeja/17516 to your computer and use it in GitHub Desktop.
Add to your spec_helper.rb to make your view spec render calls DRYer.
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
# Lets you just say 'render' in a view spec. The path is | |
# discovered from the describe block. | |
# This is here so you can config.include(RenderHelper) to use this feature. | |
module RenderHelper | |
def self.included(mod) | |
if mod.ancestors.include? Spec::Rails::Example::RailsExampleGroup | |
Spec::Rails::Example::ViewExampleGroup.instance_eval do | |
def inherited(subclass) | |
super | |
subclass.send :include, ViewExampleGroupRender | |
end | |
end | |
end | |
end | |
end | |
# This is where the magic happens. | |
module ViewExampleGroupRender | |
attr_reader :view_path | |
def initialize(defined_description, &implementation) | |
super | |
@view_path = (self.class.superclass.description_args || self.class.description_args)[0].to_s | |
end | |
def render(*args) | |
if args.empty? | |
super @view_path | |
else | |
super *args | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment