Skip to content

Commit a4837e7

Browse files
committed
Remove instance variables in generated specs
RSpec/InstanceVariable rule of rubocop-rspec gem prefers no instance variable usages in specs by default, at least v2.10.0
1 parent d556435 commit a4837e7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/generators/rspec/scaffold/templates/edit_spec.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22

33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
RSpec.describe "<%= ns_table_name %>/edit", <%= type_metatag(:view) %> do
5-
before(:each) do
6-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
5+
let(:<%= ns_file_name %>) {
6+
<%= class_name %>.create!(<%= ')' if output_attributes.empty? %>
77
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
88
<%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
99
<% end -%>
10-
<%= output_attributes.empty? ? "" : " ))\n" -%>
10+
<%= " )\n" unless output_attributes.empty? -%>
11+
}
12+
13+
before(:each) do
14+
assign(:<%= ns_file_name %>, <%= ns_file_name %>)
1115
end
1216
1317
it "renders the edit <%= ns_file_name %> form" do
1418
render
1519
16-
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
20+
assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= ns_file_name %>), "post" do
1721
<% for attribute in output_attributes -%>
1822
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
1923
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"

lib/generators/rspec/scaffold/templates/show_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
44
RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
55
before(:each) do
6-
@<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
6+
assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
77
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
88
<%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
99
<% end -%>

0 commit comments

Comments
 (0)