Rails 开发:从静态页面到动态页面的实践
1. 首次测试与新页面添加
在开发过程中,测试是确保代码质量的重要环节。我们可以通过以下命令来运行测试:
$ bundle exec rspec spec/requests/static_pages_spec.rb
1.1 添加新页面
我们将使用测试驱动开发(TDD)的方法来添加一个新页面——关于页面(About page)。TDD 的流程通常遵循红 - 绿 - 重构(Red - Green - Refactor)的循环。
- 红(Red) :编写一个失败的测试来触发红阶段。以下是测试关于页面内容的代码:
# 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_
超级会员免费看
订阅专栏 解锁全文
75

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



