Skip to content

Instantly share code, notes, and snippets.

@Peeja
Created October 17, 2008 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peeja/17516 to your computer and use it in GitHub Desktop.
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.
# 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