Rails에 익숙하지 않고 Hartl 's Rails 튜토리얼에서 8.25에 도달하기 전에 테스트가 제대로되지 않는 이유를 알 수 없습니다. 다음은 오류 및 일부 코드입니다. 나는 그것이 아마도 내가 간과 할 수있는 사소한 것이라고 생각한다. 그러나 나는 그것을 여러 번 들여다 보았다. 그리고 나는 아직도 그것을 이해할 수 없다. 어떤 도움이라도 대단히 감사합니다! 또한, 나는 더 많은 코드를 추가해야하는지 알려 주시기 바랍니다Ruby Rails 튜토리얼 8.25
1) Authentication signin with valid information
Failure/Error: it { should have_link('Settings', href: edit_user_path(user)) }
expected link "Settings" to return something
# ./spec/requests/authentication_pages_spec.rb:41:in `block (4 levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: it { should have_link('Users', href: users_path) }
expected link "Users" to return something
# ./spec/requests/authentication_pages_spec.rb:39:in `block (4 levels) in <top (required)>'
Finished in 2.38 seconds
56 examples, 2 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:41 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:39 # Authentication signin with valid information
user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_selector('title', text: 'Sign up') }
it { should have_content('error') }
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
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('[email protected]') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
end
end
end
end
authentication_pages_spec.rb
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_selector('title', text: user.name) }
it { should have_link('Users', href: users_path) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Settings', href: edit_user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
응용 프로그램/도우미/session_helper.rb
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= User.find_by_remember_token(:cookies[:remember_token])
end
end
붙여해야한다'/ 응용 프로그램/도우미/sessions_helper당신은 라인을 가지고있다. rb'. –
또한 루트 경로에 대한 템플릿이 무엇이든간에. – claptimes
아마도 정수 ('42') 대신 심볼 (': a_symbol')을 사용하여 배열에 색인을 붙이려고합니다. –