视图规范推断控制器的路径和操作

推断控制器路径

给定一个名为“spec/views/widgets/new.html.erb_spec.rb”的文件,其中包含

require "rails_helper"

RSpec.describe "widgets/new" do
  it "infers the controller path" do
    expect(controller.request.path_parameters[:controller]).to eq("widgets")
    expect(controller.controller_path).to eq("widgets")
  end
end

我运行rspec spec/views

那么示例应该全部通过。

推断操作

给定一个名为“spec/views/widgets/new.html.erb_spec.rb”的文件,其中包含

require "rails_helper"

RSpec.describe "widgets/new" do
  it "infers the controller action" do
    expect(controller.request.path_parameters[:action]).to eq("new")
  end
end

我运行rspec spec/views

那么示例应该全部通过。

不要在部分中推断操作

给定一个名为“spec/views/widgets/form.html.erbspec.rb”的文件,其中包含

require "rails_helper"

RSpec.describe "widgets/_form" do
  it "includes a link to new" do
    expect(controller.request.path_parameters[:action]).to be_nil
  end
end

我运行rspec spec/views

那么示例应该全部通过。