【发布时间】:2014-04-02 09:07:35
【问题描述】:
我遵循 M Hartl 的“Ruby on Rails 教程”,第 3.2.2 章
当我将 /static_pages/about 添加到 routes.rb 时,即使在 static_pages_controller.rb 中未定义“about”操作,rspec 测试也会通过。
快把我逼疯了!
我正在使用 ruby-2.1.1、rspec-rails 2.14.2、Capybara 2.1.0
static_pages_spec.rb:
require 'spec_helper'
describe "StaticPages" do
describe "About" do
it "should have the content 'About'" do
visit '/static_pages/about'
expect(page).to have_content('About')
end
end
end
routes.rb:
RortSampleApp::Application.routes.draw do
get "static_pages/about"
end
static_pages_controller.rb:
class StaticPagesController < ApplicationController
end
运行 rspec 测试和结果的命令:
$ rspec spec/requests/static_pages_spec.rb
.
Finished in 0.02604 seconds
1 example, 0 failures
Randomized with seed 61832
还有 test.log:
(0.1ms) begin transaction
Started GET "/static_pages/about" for 127.0.0.1 at 2014-04-02 01:59:45 -0700
AbstractController::ActionNotFound - The action 'about' could not be found for StaticPagesController:
actionpack (4.0.4) lib/abstract_controller/base.rb:131:in `process'
actionpack (4.0.4) lib/abstract_controller/rendering.rb:44:in `process'
【问题讨论】:
标签: ruby-on-rails ruby rspec capybara