class PartialTestcase::Base
Attributes
html_body[R]
Public Class Methods
partial_path(partial)
click to toggle source
# File lib/partial_testcase/base.rb, line 16 def self.partial_path(partial) self.partial = partial end
with_helpers(&block)
click to toggle source
# File lib/partial_testcase/base.rb, line 20 def self.with_helpers(&block) helpers << block end
with_module(mod)
click to toggle source
# File lib/partial_testcase/base.rb, line 24 def self.with_module(mod) modules << mod end
Public Instance Methods
assign(**assigns)
click to toggle source
# File lib/partial_testcase/base.rb, line 28 def assign(**assigns) @_assigns.merge!(assigns) end
before_setup()
click to toggle source
Calls superclass method
# File lib/partial_testcase/base.rb, line 11 def before_setup setup_view super end
Protected Instance Methods
add_test_context_inheritence(view)
click to toggle source
# File lib/partial_testcase/base.rb, line 81 def add_test_context_inheritence(view) add_to_context(Proc.new { attr_accessor :test_instance def method_missing(method, *args, &block) test_instance.send method, *args, &block end }) view.test_instance = self end
add_to_context(block)
click to toggle source
# File lib/partial_testcase/base.rb, line 74 def add_to_context(block) return if block.nil? mod = Module.new mod.class_eval(&block) @_action_view_class.include(mod) end
combined_fragment_cache_key(key)
click to toggle source
# File lib/partial_testcase/base.rb, line 42 def combined_fragment_cache_key(key) [:views, key] end
document_root_element()
click to toggle source
# File lib/partial_testcase/base.rb, line 48 def document_root_element Nokogiri::HTML(@html_body.to_s) end
method_missing(method, *args, &block)
click to toggle source
# File lib/partial_testcase/base.rb, line 84 def method_missing(method, *args, &block) test_instance.send method, *args, &block end
render_partial(*args, &block)
click to toggle source
# File lib/partial_testcase/base.rb, line 52 def render_partial(*args, &block) view = @_action_view_class.new(ApplicationController.view_paths, @_assigns) self.class.modules.each do |mod| @_action_view_class.include(mod) end self.class.helpers.each do |helper| add_to_context(helper) end add_to_context(block) add_test_context_inheritence(view) options = args.extract_options! partial_path = args[0] || self.class.partial if partial_path.nil? raise "You must specify the path of the partial you are testing. Call the class method 'partial_path'" end @html_body = view.render(partial: partial_path, locals: options) end
setup_view()
click to toggle source
# File lib/partial_testcase/base.rb, line 34 def setup_view @html_body = nil @_assigns = {} @_action_view_class = Class.new(::ActionView::Base) do def view_cache_dependencies; end def combined_fragment_cache_key(key) [:views, key] end end end
view_cache_dependencies()
click to toggle source
# File lib/partial_testcase/base.rb, line 40 def view_cache_dependencies; end