ActionController :: UnknownFormat in rspec controller after 4 rails update

I have been stuck with this issue for a day. This is what the controller looks like:

class HarvestSchedulesController < ApplicationController

  before_filter :authenticate_user!

  respond_to :json

  def show
    @harvest_schedule = HarvestSchedule.find(params[:id])
    respond_with @harvest_schedule
  end    
end

      

and spec:

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

      

When I run spec, the error is:

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)>'

      

I don't see any problem with the controller or the spec at all. The application has used Rails 3.2.12 before and all specifications have passed. This error only occurs after upgrading the Rails version to 4.1.4. I am using rspec 2.14.1. Has anyone faced a similar problem?

Greetings

+3


source to share


1 answer


You indicated that the action only responds to JSON requests:

respond_to :json

      



So, you need to request a JSON response in your spec:

get :show, id: 1, format: 'json'

      

+3


source







All Articles