我想測試我的'style.css'是否鏈接到我的頁面,同時呈現給定的佈局,例如'application.html.erb':Rspec-rails:測試佈局是否包含樣式或javascript
因此,這裏的規格:
規格/視圖/佈局/ application.html.erb_spec.rb
it 'should include styles for screen media' do
render
rendered.should have_selector('link',
:href => '/stylesheets/style.css',
:media => 'screen',
:rel => 'stylesheet',
:type => 'text/css'
)
end
而且我application.html.erb樣子:
應用程序/視圖/佈局/ application.html.erb
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<%= stylesheet_link_tag :style, :media => 'screen' %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
當我跑我的看法規範,它失敗,因爲
<link href="/stylesheets/style.css?1289599022" media="screen" rel="stylesheet" type="text/css">
呈現,並
<link rel='stylesheet' type='text/css' media='screen' href='/stylesheets/reset.css'/>
是期待。
這是關於在文件名後面添加的數字'1289599022'軌道。有關如何測試此功能的任何想法?
鑑於你所展示的規格,我不認爲你的期望會是你寫的。 – zzawaideh 2010-11-12 22:12:52
該規範根據rspec控制檯輸出真正尋找適當的鏈接標籤 – installero 2010-11-13 11:21:11
它是水豚嗎?你是如何在視圖規範中工作的? http://groups.google.com/group/ruby-capybara/browse_thread/thread/6f8188ba35e170ff – whitered 2011-01-27 13:01:10