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