Skip to content

Instantly share code, notes, and snippets.

@atwam
atwam / view_resource_macros.rb
Created May 14, 2013 20:02
Fixing rspec view specs to use inherited_resources and inherited views
module ViewResourceMacros
def has_resource(name, &block)
before do
# Creates the resource
@resource ||= yield
# Assign to the symbol we wanted, so it's available in the view
assign(name, @resource)
# Assigns to @name so that we can use that in our assertions
instance_variable_set("@#{name}", @resource)