我正在使用Ruby on Rails 3.2.2和rspec-rails-2.8.1。我想輸出關於將要運行測試的詳細信息,例如,像這樣:輸出有關將要運行的測試的更多信息是否正確?
# file_name.html.erb
...
# General idea
expected_value = ...
it "... #{expected_value}" do
...
end
# Usage that I am trying to implement
expected_page_title =
I18n.translate(
'page_title_html'
:user => @user.firstname
)
it "displays the #{expected_page_title} page title" do
view.content_for(:page_title).should have_content(expected_page_title)
end
注:「輸出」旨在爲那些輸出,當您運行rspec . --format documentation
命令行在終端窗口中。
這是一種正確的測試方式嗎?
相關問題:
在您的第一個RSpec示例中,您使用了'subject.full_name.should =='Software Guy'',但是我會使用'subject.full_name.should == expected_full_name'來幹DRY(不要重複自己)。 – Backo 2012-04-07 19:17:58