module RSpec::Rails::ViewExampleGroup::ExampleMethods
def _controller_path
def _controller_path _path_parts[0..-2].join("/") end
def _default_render_options
def _default_render_options formats = if ActionView::Template::Types.respond_to?(:symbols) ActionView::Template::Types.symbols else [:html, :text, :js, :css, :xml, :json].map(&:to_s) end.map { |x| Regexp.escape(x) }.join("|") handlers = ActionView::Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|") locales = "[a-z]{2}(?:-[A-Z]{2})?" variants = "[^.]*" path_regex = %r{ \A (?<template>.*?) (?:\.(?<locale>#{locales}))?? (?:\.(?<format>#{formats}))?? (?:\+(?<variant>#{variants}))?? (?:\.(?<handler>#{handlers}))? \z }x # This regex should always find a match. # Worst case, everything will be nil, and :template will just be # the original string. match = path_regex.match(_default_file_to_render) render_options = {template: match[:template]} render_options[:handlers] = [match[:handler]] if match[:handler] render_options[:formats] = [match[:format].to_sym] if match[:format] render_options[:locales] = [match[:locale]] if match[:locale] render_options[:variants] = [match[:variant]] if match[:variant] render_options end
def _include_controller_helpers
def _include_controller_helpers helpers = controller._helpers view.singleton_class.class_exec do include helpers unless included_modules.include?(helpers) end end
def _inferred_action
def _inferred_action _path_parts.last.split(".").first end
def _path_parts
def _path_parts _default_file_to_render.split("/") end
def params
view.
Provides access to the params hash that will be available within the
def params controller.params end
def render(options = {}, local_assigns = {}, &block)
-
render({partial: path_to_file}, {... locals ...}) do ... end
-
render({partial: path_to_file}, {... locals ...})
-
render({partial: path_to_file})
-
render
def render(options = {}, local_assigns = {}, &block) options = _default_render_options if Hash === options && options.empty? super(options, local_assigns, &block) end
def response
- Use `rendered` instead.
def response # `assert_template` expects `response` to implement a #body method # like an `ActionDispatch::Response` does to force the view to # render. For backwards compatibility, we use #response as an alias # for #rendered, but it needs to implement #body to avoid # `assert_template` raising a `NoMethodError`. unless rendered.respond_to?(:body) def rendered.body self end end rendered end
def stub_template(hash)
that is the subject of the example.
help isolate view examples from partials rendered by the view template
Rails' FixtureResolver to the front of the view_paths list. Designed to
Simulates the presence of a template on the file system by adding a
def stub_template(hash) view.view_paths.unshift(StubResolverCache.resolver_for(hash)) end
def template
- Use `view` instead.
def template RSpec.deprecate("template", replacement: "view") view end
def view
end
# ...
render
view.stub(:foo) { "foo" }
it "shows all the widgets" do
describe "widgets/new.html.erb" do
Use this to stub methods _before_ calling `render`.
The instance of `ActionView::Base` that is used to render the template.
def view _view end