Skip to content

InferredSpecType not working with Rails 8. #2815

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

Closed
joel opened this issue Nov 24, 2024 · 3 comments
Closed

InferredSpecType not working with Rails 8. #2815

joel opened this issue Nov 24, 2024 · 3 comments

Comments

@joel
Copy link
Contributor

joel commented Nov 24, 2024

The exact same view spec pass with

Ruby version: 3.3.6
Rails version: 7.2.2
RSpec version: 7.1.0

but fails with

Ruby version: 3.3.6
Rails version: 8.0.0
RSpec version: 7.1.0
require "rails_helper"

RSpec.describe "users/new" do
  before do
    assign(:user, User.new(name: "MyString"))
  end

  it "renders new user form" do
    render

    assert_select "form[action=?][method=?]", users_path, "post" do
      assert_select "input[name=?]", "user[name]"
    end
  end
end
 NoMethodError:
       undefined method `assign' for #<RSpec::ExampleGroups::UsersNew0x000000012e4d0150>
@joel
Copy link
Contributor Author

joel commented Nov 24, 2024

Okay, it feels the InferredSpecType is failing to do its job, adding type: :view make it works.

require "rails_helper"

RSpec.describe "users/new", type: :view do
  before do
    assign(:user, User.new(name: "MyString"))
  end

  it "renders new user form" do
    render

    assert_select "form[action=?][method=?]", users_path, "post" do
      assert_select "input[name=?]", "user[name]"
    end
  end
end

Is passing

@joel joel changed the title Rails 8 NoMethodError: undefined method `assign' for #<RSpec::ExampleGroups::...> InferredSpecType not working with Rails 8. Nov 24, 2024
@pirj
Copy link
Member

pirj commented Nov 24, 2024

Is this spec generated or hand-written?

With inferring option and turned off, you have to add type metadata.

The cop doesn’t fail, it is marked as unsafe and for a good reason - it has no way to know if inferring is on or off. If inferring is off, disable it immediately the cop, it’s what its doc says.

@pirj pirj closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2024
@joel
Copy link
Contributor Author

joel commented Nov 24, 2024

Okay, I see this is a recent change Comment out infer_spec_type_from_file_location! in generated rails_helper.rb, I use a template to set up my rails app, I did not spot that regression. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants