RSpecを使用してテストを実行すると、次のエラーが発生します(複数回)。
1) User Pages edit with valid information
Failure/Error: visit edit_user_path(user)
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/views/users/edit.html.haml:15:in `block in _app_views_users_edit_html_haml__2466546393595631499_70225077026800'
# ./app/views/users/edit.html.haml:6:in `_app_views_users_edit_html_haml__2466546393595631499_70225077026800'
# ./spec/requests/user_pages_spec.rb:54:in `block (3 levels) in <top (required)>'
Railsのエラーメッセージを読むことに慣れていません。これは、間違った数の引数で呼び出されているメソッドがedit.html.hamlまたはuser_pages_spec.rbにあることを示していますか?edit_user_pathが0個の引数で呼び出されているということですか?
編集してコードを追加します。
edit.html.haml:
- provide(:title, "Edit user")
%h1 Update your profile
.row
.span6.offset3
= form_for(@user) do |f|
= f.label :name
= f.text_field :name
= f.label :email
= f.text_field :email
= f.label :password
= f.password_field
= f.label :password_confirmation, "Confirm Password"
= f.password_field :password_confirmation
= f.submit "Save changes", class: "btn btn-large btn-primary"
user_pages_spec.rbの関連部分:
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
end
describe "page" do
it { should have_selector('h1', text: "Update your profile") }
it { should have_selector('title', text: "Edit user") }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new@example.com" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_selector('title', text: new_name) }
it { should have_success_message('') }
it { should have_link('Sign out', href: signout_path) }
specify { user.reload.name.should == new_name }
specify { user.reload.email.should == new_email }
end
end