Pet*_*xey 6 xml rspec ruby-on-rails
我想做一些基本的检查,以确保正确生成XML站点地图,但have_selector似乎无法检测标记:
require 'spec_helper'
describe SitemapController do
render_views
before(:all) do
# code to generate factory data
# ...
end
# illustrating the problem
it "should be able detect nodes that are definitely present" do
get :index
response.should have_selector('url')
end
end
Run Code Online (Sandbox Code Playgroud)
每次运行测试时都会出现以下错误:
RSpec::Expectations::ExpectationNotMetError: expected css "url" to return something
Run Code Online (Sandbox Code Playgroud)
正在生成站点地图,当我调试RSpec测试并查看response对象时,我可以看到xml内容:
ruby-1.9.2-p180 :001 > response.body
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n <url>\n <loc>http://test.host/panel ...
Run Code Online (Sandbox Code Playgroud)
我的站点地图由SitemapController生成,视图位于views/sitemap/index.builder.xml.
为什么没有have_selector踢?