Permalink
Browse files

Simplify the stub content generated in views in controller specs.

Closes #105.
  • Loading branch information...
dchelimsky committed Jun 28, 2010
1 parent 1c785d5 commit 121485fc5311c48749ef7421e30fb11faed7d5cd
Showing with 9 additions and 26 deletions.
  1. +9 −26 lib/rspec/rails/view_rendering.rb
@@ -20,47 +20,30 @@ def render_views?
end
end
- module ::ActionView
# Delegates find_all to the submitted controller's view_paths and then
# returns templates with modified source
- class PathSetDelegatorResolver < Resolver
+ class PathSetDelegatorResolver < ::ActionView::Resolver
attr_reader :path_set
- def initialize(controller)
- @controller = controller
- @path_set = controller.class.view_paths
+ def initialize(path_set)
+ @path_set = path_set
end
def find_all(*args)
- template_source = <<-SOURCE
-#{"*"*80}
-Template source generated by RSpec. If you prefer to render view templates
-in your specs, add render_views to the example group, like this:
-
- describe MyController do
- render_views
-
-Debug info:
-
- controller: #{@controller.class}
- resolver: #{self.class}
- args: #{args.inspect}
-#{"*"*80}
-SOURCE
-
- templates = @path_set.find_all(*args)
+ templates = path_set.find_all(*args)
templates.each do |t|
- t.singleton_class.__send__ :define_method, :source do |*|
- template_source
+ t.singleton_class.class_eval do
+ def source
+ "Template source generated by RSpec."
+ end
end
end
end
end
- end
included do
before do
- @_path_set_delegator_resolver = ::ActionView::PathSetDelegatorResolver.new(@controller)
+ @_path_set_delegator_resolver = PathSetDelegatorResolver.new(@controller.class.view_paths)
@controller.class.view_paths = ::ActionView::PathSet.new.push(@_path_set_delegator_resolver)
end

0 comments on commit 121485f

Please sign in to comment.