0
在我的Rails應用4我指定我的語言環境如下: 配置/區域設置/查看/ show_user/en.yml 的內容:RSpec的不承認我的國際化標籤
en:
activerecord:
attributes:
user:
first_name: First name
last_name: Last name
...
layouts:
header:
home: "Home"
help: "Help"
...
footer:
about: "About"
contact: "Contact"
users:
new:
signup: "Sign up!"
create_my_account: "Create my account"
當我跑我的應用程序在我的本地主機,我的所有標籤顯示正確。然而,我的RSpec的測試,
describe "with valid information" do
before do
fill_in "First name", with: "Jenny"
fill_in "Last name", with: "Johnson"
當我做如下改變我的這部分失敗時失敗,/views/users/_fields.html.erb
<%= f.label t :first_name, scope: [:activerecord, :attributes, :user] %>
<% # f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.label :last_name %>
<%= f.text_field :last_name %>
我的RSpec的測試顯示:
1) User pages signup with valid information should create a user
Failure/Error: fill_in "First name", with: "Jenny"
Capybara::ElementNotFound:
Unable to find field "First name"
# ./spec/requests/user_pages_spec.rb:88:in `block (4 levels) in <top (required)>'
我注意到我的窗體生成的html顯示first_name的不同ID,但我不知道這是否重要:
<label for="user_First name">First name</label>
<input id="user_first_name" name="user[first_name]" type="text" />
<label for="user_last_name">Last name</label>
<input id="user_last_name" name="user[last_name]" type="text" />
我的問題是:爲什麼水豚不能找到我的標籤,:first_name,而我的頁面在我的瀏覽器中正確顯示?