Skip to content

Commit 0ee856c

Browse files
author
Sam Phippen
committed
Fix template path parsing for rails versions that don't expose format symbols
1 parent 8ba6330 commit 0ee856c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/rspec/rails/example/view_example_group.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,20 @@ def rendered.body
129129

130130
def _default_render_options
131131
if ::Rails::VERSION::STRING >= '3.2'
132+
formats = if ActionView::Template::Types.respond_to?(:symbols)
133+
ActionView::Template::Types.symbols.map { |x| Regexp.escape(x) }.join("|")
134+
else
135+
[:html, :text, :js, :css, :xml, :json].map(&:to_s)
136+
end.map { |x| Regexp.escape(x) }.join("|")
137+
138+
132139
handlers = ActionView::Template::Handlers.extensions.map { |x| Regexp.escape(x) }.join("|")
133-
formats = ActionView::Template::Types.symbols.map { |x| Regexp.escape(x) }.join("|")
134140
locales = "[a-z]{2}(?:-[A-Z]{2})?"
135141
variants = "[^.]*"
136142
path_regex = %r{
137-
\A
138-
(?<template>.*?)
139-
(?:\.(?<locale>#{locales}))??
143+
\A
144+
(?<template>.*?)
145+
(?:\.(?<locale>#{locales}))??
140146
(?:\.(?<format>#{formats}))??
141147
(?:\+(?<variant>#{variants}))??
142148
(?:\.(?<handler>#{handlers}))?

0 commit comments

Comments
 (0)