저는 Michael Hartl의 Ruby on Rails 튜토리얼에서 7 장에 머물러 있습니다.RoR, 오류/오류 : 기대 {클릭 버튼 제출} .not_to 변경 (사용자, : 개수)
내 routes.rb
SampleApp::Application.routes.draw do
get "users/new"
resources :users
root 'static_pages#home'
match '/signup', to: 'users#new', via: 'get'
match '/help', to: 'static_pages#help', via: 'get'
match '/about', to: 'static_pages#about', via: 'get'
match '/contact', to: 'static_pages#contact', via: 'get'
end
내 사양/요청/user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
let(:submit) { "Create my account" }
let(:submit) { "Sign up" }
it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
end
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
내 애플/뷰/사용자/new.html.erb
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
그리고 테스트를 실행하려고하면 다음과 같이 표시됩니다.
[email protected]:~/rails_projects/sample_app$ bundle exec rspec spec/
...............FF......................
Failures:
1) User pages with invalid information should not create a user
Failure/Error: expect { click_button submit }.not_to change(User, :count)
NameError:
undefined local variable or method `submit' for #<RSpec::Core::ExampleGroup::Nested_4::Nested_3:0xad40120>
# ./spec/requests/user_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:27:in `block (3 levels) in <top (required)>'
2) User pages with valid information should create a user
Failure/Error: fill_in "Name", with: "Example User"
Capybara::ElementNotFound:
Unable to find field "Name"
# ./spec/requests/user_pages_spec.rb:33:in `block (3 levels) in <top (required)>'
Finished in 1.54 seconds
39 examples, 2 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:26 # User pages with invalid information should not create a user
rspec ./spec/requests/user_pages_spec.rb:39 # User pages with valid information should create a user
누군가이 시험에 실패한 이유를 설명해주십시오.
'click_button : submit'이 아니어야합니까? – BroiSatse
실례합니다 ... 무슨 뜻인가요? 예상 {click_button : submit} 기대에 {click_button : submit} 기대 하시겠습니까? – Gvyntyk
당신이 기호''submit'을 전달해야하는 동안 당신이 정의되지 않은'submit' 메소드를 실행하려한다는 것을 의미합니다. – BroiSatse