我正在寫一些規範,下面的失敗,但頁面/ 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