【发布时间】:2014-08-14 22:20:33
【问题描述】:
我在这个问题上纠结了一天。这是控制器的样子:
class HarvestSchedulesController < ApplicationController
before_filter :authenticate_user!
respond_to :json
def show
@harvest_schedule = HarvestSchedule.find(params[:id])
respond_with @harvest_schedule
end
end
和规格:
let(:schedule) { mock_model(HarvestSchedule).as_null_object }
describe "GET show" do
before(:each) do
HarvestSchedule.stub(:find).with("1") { schedule }
end
it "finds the harvest schedule" do
HarvestSchedule.should_receive(:find).with("1") { schedule }
get :show, id: 1
assigns(:harvest_schedule).should eq schedule
end
end
当我运行规范时,错误是:
Failure/Error: HarvestSchedule.should_receive(:find).with("1") { schedule }
ActionController::UnknownFormat:
ActionController::UnknownFormat
# ./app/controllers/harvest_schedules_controller.rb:29:in `show'
# ./spec/controllers/harvest_schedules_controller_spec.rb:41:in `block (3 levels) in <top (required)>'
我根本看不出控制器或规格有任何问题。该应用程序之前使用的是 Rails 3.2.12,并且所有规范都通过了。只有在我将 Rails 版本升级到 4.1.4 后才会出现此错误。我正在使用 rspec 2.14.1。有没有人遇到过类似的问题?
干杯
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 rspec-rails