Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment out infer_spec_type_from_file_location! in generated helper. #2804

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Enhancements:

* Improve implicit description for ActionCable matchers `have_broadcasted_to` /
`have_broadcast`. (Simon Fish, #2795)
* Comment out `infer_spec_type_from_file_location!` in newly generated
`rails_helper.rb` files. (Jon Rowe, #2804)

Bug Fixes:

Expand Down
2 changes: 1 addition & 1 deletion features/matchers/redirect_to_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: `redirect_to` matcher
"""ruby
require "rails_helper"

RSpec.describe WidgetsController do
RSpec.describe WidgetsController , type: :controller do

describe "#create" do
subject { post :create, :params => { :widget => { :name => "Foo" } } }
Expand Down
6 changes: 3 additions & 3 deletions features/matchers/render_template_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: `render_template` matcher
"""ruby
require "rails_helper"

RSpec.describe GadgetsController do
RSpec.describe GadgetsController , type: :controller do
describe "GET #index" do
subject { get :index }

Expand All @@ -38,7 +38,7 @@ Feature: `render_template` matcher
"""ruby
require "rails_helper"

RSpec.describe GadgetsController do
RSpec.describe GadgetsController , type: :controller do
describe "GET #index" do
subject { get :index }

Expand All @@ -60,7 +60,7 @@ Feature: `render_template` matcher
"""ruby
require "rails_helper"

RSpec.describe "gadgets/index" do
RSpec.describe "gadgets/index" , type: :view do
it "renders the index template" do
assign(:gadgets, [Gadget.create!])
render
Expand Down
6 changes: 3 additions & 3 deletions features/matchers/send_email_matcher.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: `send_email` matcher
"""ruby
require "rails_helper"

RSpec.describe NotificationsMailer do
RSpec.describe NotificationsMailer , type: :mailer do
it "checks email sending by multiple params" do
expect {
NotificationsMailer.signup.deliver_now
Expand All @@ -36,7 +36,7 @@ Feature: `send_email` matcher
"""ruby
require "rails_helper"

RSpec.describe NotificationsMailer do
RSpec.describe NotificationsMailer , type: :mailer do
it "checks email sending by one param only" do
expect {
NotificationsMailer.signup.deliver_now
Expand All @@ -54,7 +54,7 @@ Feature: `send_email` matcher
"""ruby
require "rails_helper"

RSpec.describe NotificationsMailer do
RSpec.describe NotificationsMailer , type: :mailer do
it "checks email not sent" do
expect {
NotificationsMailer.signup.deliver_now
Expand Down
6 changes: 3 additions & 3 deletions features/view_specs/inferred_controller_path.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: View specs infer controller's path and action
"""ruby
require "rails_helper"

RSpec.describe "widgets/new" do
RSpec.describe "widgets/new" , type: :view do
it "infers the controller path" do
expect(controller.request.path_parameters[:controller]).to eq("widgets")
expect(controller.controller_path).to eq("widgets")
Expand All @@ -20,7 +20,7 @@ Feature: View specs infer controller's path and action
"""ruby
require "rails_helper"

RSpec.describe "widgets/new" do
RSpec.describe "widgets/new" , type: :view do
it "infers the controller action" do
expect(controller.request.path_parameters[:action]).to eq("new")
end
Expand All @@ -34,7 +34,7 @@ Feature: View specs infer controller's path and action
"""ruby
require "rails_helper"

RSpec.describe "widgets/_form" do
RSpec.describe "widgets/_form" , type: :view do
it "includes a link to new" do
expect(controller.request.path_parameters[:action]).to be_nil
end
Expand Down
4 changes: 2 additions & 2 deletions features/view_specs/stub_template.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Using `stub_template`
"""ruby
require "rails_helper"

RSpec.describe "gadgets/list" do
RSpec.describe "gadgets/list" , type: :view do
it "renders the gadget partial for each gadget" do
assign(:gadgets, [
double(:name => "First"),
Expand All @@ -34,7 +34,7 @@ Feature: Using `stub_template`
"""ruby
require "rails_helper"

RSpec.describe "gadgets/edit" do
RSpec.describe "gadgets/edit" , type: :view do
before(:each) do
@gadget = assign(:gadget, Gadget.create!)
end
Expand Down
28 changes: 14 additions & 14 deletions features/view_specs/view_spec.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "widgets/index" do
RSpec.describe "widgets/index" , type: :view do
it "displays all the widgets" do
assign(:widgets, [
Widget.create!(:name => "slicer"),
Expand All @@ -49,7 +49,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "widgets/index" do
RSpec.describe "widgets/index" , type: :view do

context "with 2 widgets" do
before(:each) do
Expand All @@ -76,7 +76,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "rendering the widget template" do
RSpec.describe "rendering the widget template" , type: :view do
it "displays the widget" do
assign(:widget, Widget.create!(:name => "slicer"))

Expand All @@ -98,7 +98,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "rendering the widget template" do
RSpec.describe "rendering the widget template" , type: :view do
context "with the inventory layout" do
it "displays the widget" do
assign(:widget, Widget.create!(:name => "slicer"))
Expand Down Expand Up @@ -126,15 +126,15 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "widgets/widget.html.erb" do
RSpec.describe "widgets/widget.html.erb" , type: :view do
it "renders the HTML template" do
render

expect(rendered).to match /HTML/
end
end

RSpec.describe "widgets/widget.xml.erb" do
RSpec.describe "widgets/widget.xml.erb" , type: :view do
it "renders the XML template" do
render

Expand All @@ -158,7 +158,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "widgets/index" do
RSpec.describe "widgets/index" , type: :view do
it "displays the widget" do
widget = Widget.create!(:name => "slicer")

Expand All @@ -180,7 +180,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "rendering locals in a partial" do
RSpec.describe "rendering locals in a partial" , type: :view do
it "displays the widget" do
widget = Widget.create!(:name => "slicer")

Expand All @@ -202,7 +202,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "rendering locals in a partial" do
RSpec.describe "rendering locals in a partial" , type: :view do
it "displays the widget" do
widget = Widget.create!(:name => "slicer")

Expand All @@ -224,7 +224,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "rendering text directly" do
RSpec.describe "rendering text directly" , type: :view do
it "displays the given text" do

render :plain => "This is directly rendered"
Expand Down Expand Up @@ -255,7 +255,7 @@ Feature: View specs
"""ruby
require 'rails_helper'

RSpec.describe 'secrets/index' do
RSpec.describe 'secrets/index' , type: :view do
before do
allow(view).to receive(:admin?).and_return(true)
end
Expand All @@ -274,7 +274,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "controller.request.path_parameters" do
RSpec.describe "controller.request.path_parameters" , type: :view do
it "matches the Rails environment by using symbols for keys" do
[:controller, :action].each { |k| expect(controller.request.path_parameters.keys).to include(k) }
end
Expand All @@ -288,7 +288,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "widgets/index" do
RSpec.describe "widgets/index" , type: :view do
it "has a request.fullpath that is defined" do
expect(controller.request.fullpath).to eq widgets_path
end
Expand All @@ -302,7 +302,7 @@ Feature: View specs
"""ruby
require "rails_helper"

RSpec.describe "widgets/show" do
RSpec.describe "widgets/show" , type: :view do
it "displays the widget with id: 1" do
widget = Widget.create!(:name => "slicer")
controller.extra_params = { :id => widget.id }
Expand Down
18 changes: 10 additions & 8 deletions lib/generators/rspec/install/templates/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@
# config.use_transactional_fixtures = true

<% end -%>
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
# RSpec Rails uses metadata to mix in different behaviours to your tests,
# for example enabling you to call `get` and `post` in request specs. e.g.:
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, type: :controller do
# RSpec.describe UsersController, type: :request do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://rspec.info/features/7-0/rspec-rails
config.infer_spec_type_from_file_location!
#
# You can also this infer these behaviours automatically by location, e.g.
# /spec/models would pull in the same behaviour as `type: :model` but this
# behaviour is considered legacy and will be removed in a future version.
#
# To enable this behaviour uncomment the line below.
# config.infer_spec_type_from_file_location!

# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
Expand Down