使用 i18n 取代直接測試字串

spec/support/i18n.rb

RSpec.configure do |config|
  config.include ActionView::Helpers::TranslationHelper
end
  scenario "invalid" do
      course_form.create "", ""
 -    expect(page).to have_text("Add a course")
 +    expect(page).to have_text t("courses.new.add_course")
    end

config/locales/en.yml

en:
  courses:
    new:
      add_course: "Add a course"

app/views/courses/new.html.erb

<div class="col-md-12">

 -  <h2> Add a course </h2>
 +  <h2> <%= t(".add_course") %> </h2>
    <%= simple_form_for @course do |f| %>
      <%= f.input :title %>
      <%= f.input :description %>

results matching ""

    No results matching ""