Rails 开发:从静态页面到动态优化
1. 首次测试与新页面添加
在开发过程中,测试是确保代码质量的重要环节。当我们运行测试时,可使用以下命令:
$ bundle exec rspec spec/requests/static_pages_spec.rb
为了添加一个新页面,比如“About”页面,我们采用测试驱动开发(TDD)的方法。
- 编写失败测试(Red) :
首先,我们要为“About”页面编写一个失败的测试。以下是添加到 spec/requests/static_pages_spec.rb 文件中的测试代码:
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
page.should have_content('Sample App')
end
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
page.should have_content('Help')
end
超级会员免费看
订阅专栏 解锁全文
78

被折叠的 条评论
为什么被折叠?



