即時通訊工作ruby.railstutorial.org/ruby-on-rails-tutorial-book 。 即時通訊使用導軌3.2.7,叉勺,RSpec的,水豚,launchy和一些警衛:)使用規範進行測試,來自railstutorial第3章的水豚不起作用(have_selector('title',::text =>'| Home'))
我在第3章與測試一個很奇怪的問題:
好像測試的arent工作是什麼在<head>
-Tag內。如果我把<title>
-tag放在<body>
-tag裏面,而不是頭標籤,它可以正常工作。 它也適用於當我把<h1>
-標籤<title>
以上<head>
-標籤。這很奇怪,不是嗎?
請幫我解決問題。
的示例是從:ruby.railstutorial.org/chapters/static-pages#code:title_test:
it "should have the right title" do
visit '/static_pages/home'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App | Home")
end
誤差信息是:
Failures:
1) Static pages Home page should have the title 'Home' Failure/Error: page.should have_selector('title', :text => ' | Home') Capybara::ExpectationNotMet: expected to find css "title" with text " | Home" but there were no matches. Also found "", which matched the selector but not all filters. # ./spec/requests/static_pages_spec.rb:15:in `block (3 levels) in '
那一個是工作:
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
呈現的HTML文件:
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails Tutorial Sample App | Home</title>
<!-- some css,js stuff -->
</head>
<body>
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application
</p>
</body>
</html>
感謝
編輯: 你能找到的文件即時通訊與GitHub上的工作: https://github.com/farukg/sample_app/
鏈接到spec文件: https://github.com/farukg/sample_app/blob/master/spec/requests/static_pages_spec.rb
我所做的解釋: 主頁的代碼就像它應該是的。 關於頁面的代碼具有其自己的佈局,其中h1標籤位於title-tag之上,以顯示它適用於某種原因。 最後,幫助頁面的標題標籤也在其中起作用。
我絕對困惑,爲什麼我有這樣一個奇怪的行爲?
後衛的完整輸出:
> Run all
Bundle already up-to-date
Running all specs
Running tests with args ["--drb", "--colour", "-f", "progress", "-r", "/home/faruk/.rvm/gems/ruby-1.9.3-p125/gems/guard-rspec-1.2.0/lib/guard/rspec/formatters/notification_rspec.rb", "-f", "Guard::RSpec::Formatter::NotificationRSpec", "--out", "/dev/null", "--failure-exit-code", "2", "spec"]...
..FFF.....Neues Fenster in aktueller Browsersitzung erstellt.
.FF..
Failures:
1) Static pages Home page having application layout should have_selector head title 'Home'
Failure/Error: page.should have_selector('head title',
Capybara::ExpectationNotMet:
expected to find css "head title" with text "Ruby on Rails Tutorial Sample App | Home" but there were no matches. Also found "", which matched the selector but not all filters.
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
2) Static pages Home page having application layout should have content 'Home'
Failure/Error: page.should have_content("Ruby on Rails Tutorial Sample App | Home")
expected there to be text "Ruby on Rails Tutorial Sample App | Home" in "Sample App This is the home page for the Ruby on Rails Tutorial sample application"
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
3) Static pages Home page having application layout should have css title 'Home'
Failure/Error: page.should have_css("title", :text => "Ruby on Rails Tutorial Sample App | Home")
Capybara::ExpectationNotMet:
expected to find css "title" with text "Ruby on Rails Tutorial Sample App | Home" but there were no matches. Also found "", which matched the selector but not all filters.
# ./spec/requests/static_pages_spec.rb:36:in `block (3 levels) in <top (required)>'
4) Static pages about page with own layout should JUST have_selector head title
Failure/Error: page.should have_selector('head title')
Capybara::ExpectationNotMet:
expected to find css "head title" but there were no matches
# ./spec/requests/static_pages_spec.rb:86:in `block (3 levels) in <top (required)>'
5) Static pages about page with own layout should have_selector head title 'About Us'
Failure/Error: page.should have_selector('head title',
Capybara::ExpectationNotMet:
expected to find css "head title" with text "Ruby on Rails Tutorial Sample App | About Us" but there were no matches
# ./spec/requests/static_pages_spec.rb:93:in `block (3 levels) in <top (required)>'
Finished in 0.66215 seconds
15 examples, 5 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:20 # Static pages Home page having application layout should have_selector head title 'Home'
rspec ./spec/requests/static_pages_spec.rb:27 # Static pages Home page having application layout should have content 'Home'
rspec ./spec/requests/static_pages_spec.rb:33 # Static pages Home page having application layout should have css title 'Home'
rspec ./spec/requests/static_pages_spec.rb:83 # Static pages about page with own layout should JUST have_selector head title
rspec ./spec/requests/static_pages_spec.rb:90 # Static pages about page with own layout should have_selector head title 'About Us'
Done.
> Neues Fenster in aktueller Browsersitzung erstellt.
Neues Fenster in aktueller Browsersitzung erstellt.
你保存了你的文件嗎? – Dougui 2012-07-30 17:33:16
是的,當然,我也使用了save_and_open_page,這樣我就可以看到更改 – farukg 2012-07-30 17:37:57
似乎你無法查詢水豚2.0中的