Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix rendering deprecations in view specs

render(:template=>'new.erb') is now deprecated and should be render(:template=>'new', :handlers=>['erb']).  This patch takes the default template name supplied in the spec and breaks it up into its separate components before calling render().
  • Loading branch information...
commit 656ff350fe82123e7013a1a11335f151d8edfe49 1 parent 3562f8f
@jdelStrother jdelStrother authored
View
15 lib/rspec/rails/example/view_example_group.rb
@@ -42,7 +42,7 @@ module ExampleMethods
# end
# end
def render(options={}, local_assigns={}, &block)
- options = {:template => _default_file_to_render} if Hash === options and options.empty?
+ options = _default_render_options if Hash === options and options.empty?
super(options, local_assigns, &block)
end
@@ -98,6 +98,19 @@ def _default_file_to_render
example.example_group.top_level_description
end
+ def _default_render_options
+ # pluck the handler, format, and locale out of, eg, posts/index.de.html.haml
+ template, *components = _default_file_to_render.split('.')
+ handler, format, locale = *components.reverse
+
+ render_options = {:template => template}
+ render_options[:handlers] = [handler] if handler
+ render_options[:formats] = [format] if format
+ render_options[:locales] = [locale] if locale
+
+ render_options
+ end
+
def _path_parts
_default_file_to_render.split("/")
end
View
11 spec/rspec/rails/example/view_example_group_spec.rb
@@ -108,10 +108,15 @@ def _assigns
end
context "given no input" do
- it "sends render(:file => (described file)) to the view" do
- view_spec.stub(:_default_file_to_render) { "widgets/new.html.erb" }
+ it "sends render(:template => (described file)) to the view" do
+ view_spec.stub(:_default_file_to_render) { "widgets/new" }
view_spec.render
- view_spec.received.first.should == [{:template => "widgets/new.html.erb"},{}, nil]
+ view_spec.received.first.should == [{:template => "widgets/new"},{}, nil]
+ end
+ it "converts the filename components into render options" do
+ view_spec.stub(:_default_file_to_render) { "widgets/new.en.html.erb" }
+ view_spec.render
+ view_spec.received.first.should == [{:template => "widgets/new", :locales=>['en'], :formats=>['html'], :handlers=>['erb']},{}, nil]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.