[英]Failing rspec test
我的Rspec測試_pages_spec.rb失敗。 我正在關注Micheal Hartl的Rails教程。
當我在第83行有第二個“結束”時,所有測試都通過了,但只有一個:
Failures:
1) User pages signup edit with valid information
←[31mFailure/Error:←[0m ←[31mit { should have_selector('div.alert.alert-suc
cess') }←[0m
←[31mexpected css "div.alert.alert-success" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:77:in `block (5 levels) in <top (
required)>'←[0m
Finished in 1.28 seconds
←[31m60 examples, 1 failure←[0m
Failed examples:
←[31mrspec ./spec/requests/user_pages_spec.rb:77←[0m ←[36m# User pages signup ed
it with valid information ←[0m
這是代碼:
require 'spec_helper'
describe "User pages" do
subject { page }
let (:base_title) {"Tom Gong's Sample App"}
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', content: "#{base_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: "user@example.com"
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('user@example.com') }
it { should have_selector('title', text:user.name) }
it { should have_selector('div.alert.alert-success', text:'Welcome') }
end
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before { visit edit_user_path(user) }
describe "page" do
it { should have_selector('h1', text: "Update your profile") }
it { should have_selector('title', text:"Edit user") }
it { should have_selector('a', href: 'http://gravatar.com/emails') }
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_selector('div.alert.alert-success') }
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
end
end
誰能找到問題?
用戶頁面注冊使用有效信息進行編輯
看起來是這樣的:
User pages
|- signup
|- edit
|- with valid information
它應該是
用戶頁面使用有效信息進行編輯
即
User pages
|- edit
|- with valid information
當前編輯在注冊下描述。 那不是很正確。
我在第83行有第二個“結尾”
它應該在53行之后而不是83行之后。即在describe "edit" do
。
使用一致的縮進,您無需猜測匹配end
,這從代碼中應該顯而易見。
錯誤消息告訴您該頁面沒有選擇器'div.alert.alert-success'. It looks like the error is related to this line:
'div.alert.alert-success'. It looks like the error is related to this line:
它{應該具有_selector('div.alert.alert-success',文本:'Welcome')}}
save_and_open_page
有一個名為save_and_open_page
的漂亮方法,可讓您檢查save_and_open_page
解析的HTML文件。 調用此方法並查看源以檢查對您不起作用的選擇器。 如果仍然遇到問題,請在問題中粘貼與選擇器相對應的HTML。
您應該清理代碼的格式,因為空格和縮進不一致會很難閱讀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.