我正在写一些规范,下面的失败,但页面/ menus/1在浏览器中加载罚款。这是一个php应用程序的端口,并且是我第一次使用RSpec。任何想法,为什么它可能不工作。Rails 3.1,RSpec - 失败,但页面加载正常
错误是:
1) MenusController GET 'show' should be succesful
Failure/Error: get :show, :id => 1
ActiveRecord::RecordNotFound:
Couldn't find MenuHeader with id=1
# ./app/controllers/menus_controller.rb:18:in `show'
# ./spec/controllers/menus_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
但具体MenuHeader并基于所有正常标准(控制台,MySQL和浏览器)存在。我敢肯定,99%我有一个错误在我的规格:
require 'spec_helper'
describe MenusController do
describe "GET 'show'" do
it "should be succesful" do
get :show, :id => 1
response.should be_success
end
end
end
这里是menus_controller.rb
def show
@menu_header_data=MenuHeader.find(params[:id])
respond_to do |format|
format.html # show.html.erb
# format.json { render json: @menu } to do
end
end
THX
另外:你有一个测试“获取显示与不存在的ID应该失败”? – Zabba
现在正在处理它 – timpone
您是否正在对测试数据库运行此操作?你在使用固定装置或工厂吗? – zetetic