我正在嘗試使用Capybara RSpec匹配器來測試演示者方法。如何使用Capybara Rspec Matchers測試主持人?
可以說我有一個呈現按鈕的方法。這將是考驗我,如果我不使用水豚的RSpec匹配器寫:
it "should generate a button" do
template.should_receive(:button_to).with("Vote").
and_return("THE_HTML")
subject.render_controls.should be == "THE_HTML"
end
使用水豚rspec的匹配器,我想這樣做:
it "should render a vote button" do
subject.render_controls.should have_button('Vote')
end
這種方法是本文提出http://devblog.avdi.org/2011/09/06/making-a-mockery-of-tdd/。在文章中,作者解釋如下:「我決定改變我的規格設置,以便傳入一個模板對象,其中包含實際的Rails標記助手,然後我將Capybara規範匹配器包含在HTML中進行斷言「。
但是,我不明白這一點。當render_controls僅返回content_tag時,如何使用capybara rspec匹配器?