1
如何在不使用完整Rails堆棧的情況下測試我的ActionView擴展(例如新助手)?用於測試的ActionView不帶Rails
我使用RSpec,所以我有辦法從spec_helper.rb中從我的/ spec/views /文件夾渲染模板。什麼是最好的方式來做到這一點?
如何在不使用完整Rails堆棧的情況下測試我的ActionView擴展(例如新助手)?用於測試的ActionView不帶Rails
我使用RSpec,所以我有辦法從spec_helper.rb中從我的/ spec/views /文件夾渲染模板。什麼是最好的方式來做到這一點?
我可能不會回答你的問題,但你可以使用RSpec與rspec-rails gem。不需要在Rails棧外進行測試。
https://github.com/rspec/rspec-rails
下面是一個例子:
describe "lists/show.html.erb" do
before(:each) do
assign :new_link, Link.new
@link = mock_model(Link,
:title => "Link's title",
:url => "http://wwww.link.s.url/")
@list = mock_model(List,
:title => "Some title",
:links => [@link])
end
it "displays the list's title" do
render
rendered.should have_content(@list.title)
end
it "displays the links's title and URL" do
render
rendered.should have_link(@link.title,
:href => @link.url)
end
end
你將不得不去適應你的Gemfile(見超越鏈接)並運行bundle update
& rails rspec:install
。
謝謝。事實上,渲染/渲染解決方案無需使用導軌。 – Ximik 2012-03-05 15:31:52