我使用导轨3.2.7,spork,rspec,capybara,launchy和一些守卫:)
在第3章中,我有一个非常奇怪的问题:测试:
似乎测试并不适用于< head> -Tag内的内容.如果我将< Title> – 标签放在< body> – 标签内,而不是标题,它可以正常工作.
当我将< h1> – 标签放在< Title>在< head> -Tags内.这是奇怪的,不是吗?
请帮我弄清楚.
示例来自: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/
指向规范文件的链接:
https://github.com/farukg/sample_app/blob/master/spec/requests/static_pages_spec.rb
我所做的说明
主页的代码就像它应该是.
关于页面的代码具有自己的布局,在标题标签之上带有h1标签,以显示它的工作原理.
最后,帮助页面的标题标签也在正文标签内.
我绝对困惑,为什么我有这样一个奇怪的行为?
完整的卫兵输出:
> Run allBundle already up-to-dateRunning all specsRunning 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","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 seconds15 examples,5 failuresFailed 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.解决方法 我刚刚检查了你在Github上的项目,似乎你正在使用边缘版本的capybara:
的Gemfile
gem 'capybara',:git => 'git://github.com/jnicklas/capybara.git'
Gemfile.lock的
GIT remote: git://github.com/jnicklas/capybara.git revision: e561d249555195cdd0e9251246fc75aae876f833 specs: capybara (2.0.0.beta2) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) selenium-webdriver (~> 2.0) xpath (~> 1.0.0.beta1)
如果没有别的,我敢说这是你问题的原因. (当然,在更新capybara之后,我的reference project全部坏了,使用边缘版本)
因此,除非您热衷于帮助Capybara 2的beta测试,否则您将很乐意遵守here所列的1.1.2版本.
总结以上是内存溢出为你收集整理的测试规范,来自railstutorial第3章的capybara不起作用(have_selector(‘title’,:text =>’| Home’))全部内容,希望文章能够帮你解决测试规范,来自railstutorial第3章的capybara不起作用(have_selector(‘title’,:text =>’| Home’))所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)