title: Rspec - controller test error - Paperclip::AdapterRegistry::NoHandlerError: No handler found for "#<File:0x531beb0>"
body: <p>I asked about my Rspec test as follow.</p>
  
  <p><strong><a href="https://stackoverflow.com/questions/20148196/rspec-runtimeerror-called-id-for-nil-which-would-mistakenly-be-4">Rspec - RuntimeError: Called id for nil, which would mistakenly be 4</a></strong></p>
  
  <p>On the same code (Rspec test for "items_controller.rb"), I am trying to make the test for "PUT update". However I got the error "Paperclip::AdapterRegistry::NoHandlerError:   No handler found for "#". </p>
  
  <p>My Rspec test is as follow. Honestly, I guess that the cause of this fail is ""photo" => File.new(Rails.root + 'app/assets/images/rails.png')" on "let(:valid_attributes)". However, I tried several ways but I couldn't fix. 
  By the way, my rails version is "Rails 3.2.14". Then I tried following post, but also couldn't.</p>
  
  <p><strong><a href="https://stackoverflow.com/questions/15342031/cant-figure-out-whats-causing-my-tests-to-fail">Can&#39;t figure out what&#39;s causing my tests to fail</a></strong></p>
  
  <p>The error is as follows.</p>
  
  <pre><code>......F....
  
  Failures:
  
    1) ItemsController PUT update could not update successfully
       Failure/Error: put :update, {:id =&gt; item.to_param, :item =&gt; valid_attributes}, valid_session
       Paperclip::AdapterRegistry::NoHandlerError:
       No handler found for "#&lt;File:0x5d4c548&gt;"
       # ./app/controllers/items_controller.rb:110:in `block in update'
       # ./app/controllers/items_controller.rb:108:in `update'
       # ./spec/controllers/items_controller_spec.rb:95:in `block (3 levels) in &lt;top (required)&gt;'
  
   Finished in 1.75 seconds
   11 examples, 1 failure
  
   Failed examples:
  
   rspec ./spec/controllers/items_controller_spec.rb:91 # ItemsController PUT update could not update successfully
  
   Randomized with seed 40912
  </code></pre>
  
  <p>My Rspec test is as follows.</p>
  
  <pre><code>require 'spec_helper'
  require 'date'
  
  describe ItemsController do
  
    let(:valid_attributes) { {
      "days" =&gt; "1",
      "hours" =&gt; "1",
      "minutes" =&gt; "1",
      "name"=&gt;"HogeHoge" ,
      "category" =&gt; "Gift",
      "min_bid_price" =&gt; "100.0",
      "description" =&gt; "HogeHoge",
      "photo" =&gt; File.new(Rails.root + 'app/assets/images/rails.png')
     } }
  
    let(:valid_session) { {} }
  
    it "returns http success" do
      get "index"
      response.should be_success
    end
    it "returns http success" do
      get "new"
      response.should be_success
    end
  
    describe "POST create" do
      it "" do
      #declare the objects and stubs
      current_user = User.new(id:'1')
      current_user.save
      #"current_user=(user)" function on controller
      controller.current_user = current_user
      #auction
      auction = Auction.new(id:'1',highest_bid_id:'1', extend_bit:'1')
      auction.save
      Auction.stub(:find_by_id).and_return(auction)
      #bid
      bid = Bid.new(auction_id:'1',amount:'150.0')
      bid.save
      Bid.stub(:find_by_id).and_return(bid)
      #item
      item = Item.new(id:'1',auction_id:'1',min_bid_price:'100.0')
      item.save
      Item.stub(:find_by_id).and_return(item)
      date = DateTime.now
      post :create, {:item =&gt; {'id' =&gt; '2','days'=&gt;'1','hours'=&gt;'1','minutes'=&gt;'1','created_at'=&gt;date}}
      response.should be_success
     end
    end
  
   describe "GET index" do
    it "assigns all items as @items" do
    item = Item.create! valid_attributes
    get :index, {}, valid_session
    assigns(:items).should eq([item])
   end
  end
  describe "GET show" do
    it "assigns the requested item as @item" do
     item = Item.create! valid_attributes
     get :show, {:id =&gt; item.to_param}, valid_session
     assigns(:item).should eq(item)
    end
  end
  
  describe "GET new" do
   it "assigns a new item as @item" do
     get :new, {}, valid_session
     assigns(:item).should be_a_new(Item)
   end
  end
  
  describe "GET edit" do
   it "assigns the requested item as @item" do
     item = Item.create! valid_attributes
     get :edit, {:id =&gt; item.to_param}, valid_session
     assigns(:item).should eq(item)
   end
  end
  
  describe "PUT update" do
    it "could not update successfully" do
      item = Item.create! valid_attributes
      # Trigger the behavior that occurs when invalid params are submitted
      Item.any_instance.stub(:save).and_return(false)
      put :update, {:id =&gt; item.to_param, :item =&gt; valid_attributes}, valid_session
      assigns(:item).should eq(item)
      response.should redirect_to(@item)
    end
  
    it "could not update successfully" do
      item = Item.create! valid_attributes
      # Trigger the behavior that occurs when invalid params are submitted
      Item.any_instance.stub(:save).and_return(false)
      put :update, {:id =&gt; item.to_param, :item =&gt; { }}, valid_session
      response.should render_template("edit")
    end
  end
  
  describe "DELETE destroy" do
   it "destroys the requested item" do
     item = Item.create! valid_attributes
     expect {
      delete :destroy, {:id =&gt; item.to_param}, valid_session
     }.to change(Item, :count).by(-1)
   end
  
    it "redirects to the items list" do
     item = Item.create! valid_attributes
     delete :destroy, {:id =&gt; item.to_param}, valid_session
     response.should redirect_to(items_url)
    end
   end
  end
  </code></pre>
  
  <p>My "items_controller.rb" is as follw.</p>
  
  <pre><code>require 'timers'
  
  class ItemsController &lt; ApplicationController
  
    #instance of current user
    def current_user=(user)
     @current_user ||= user
    end
  
   def extendtimer
     Auction.find_by_id(@auction_id).update_attributes(:extend_bit =&gt; 0)
     @exp = Auction.find_by_id(@auction_id).exp_time + 2.minutes
     Auction.find_by_id(@auction_id).update_attributes(:exp_time =&gt; @exp)
     @min = Item.find_by_id(@item_id).minutes + 2
     Item.find_by_id(@item_id).update_attributes(:minutes =&gt; @min)
     @timer2 = Timers.new
     @extend_timer = @timer2.after(120){ buy }
     @timer2.wait
   end
  
   def buy
     if Auction.find_by_id(@auction_id).extend_bit == 1
       extendtimer
     else
       if Auction.find_by_id(@auction_id).highest_bid_id != 0
         Item.find_by_auction_id(@auction_id).update_attributes(:sold =&gt; 1, :sold_to =&gt;       Bid.find_by_id(Auction.find_by_id(@auction_id).highest_bid_id).user_id )
         MyMailer.auction_winner_email(Auction.find_by_id(@auction_id)).deliver
       else
         Item.find_by_auction_id(@auction_id).update_attributes(:sold =&gt; 0, :sold_to =&gt; 0    )
         MyMailer.no_bids_email(Auction.find_by_id(@auction_id)).deliver
       end
       @t1.join
     end
   end
  
   def index
     @items = Item.all
  
     respond_to do |format|
       format.html # index.html.erb
       format.json { render json: @items }
    end
   end
  
   # GET /items/1
   # GET /items/1.json
   def show
     @item = Item.find(params[:id])
     respond_to do |format|
       #format.html # show.html.erb
       format.html { render layout: (request.headers["X-Requested-With"] != 'XMLHttpRequest') }
       format.json { render json: @item }
     end
   end
  
   # GET /items/new
   # GET /items/new.json
   def new
     @item = Item.new
     respond_to do |format|
       format.html # new.html.erb
       format.json { render json: @item }
     end
   end
  
   # GET /items/1/edit
   def edit
     @item = Item.find(params[:id])
   end
  
   # POST /items
   # POST /items.json
   def create
     @item = Item.new(params[:item])
     @item.user_id = current_user.id
     respond_to do |format|
       if @item.save
         format.html { redirect_to @item, notice: 'Item was successfully created.' }
         format.json { render json: @item, status: :created, location: @item }
       else
         format.html { render action: "new" }
         format.json { render json: @item.errors, status: :unprocessable_entity }
       end
     end
     @elapsed_seconds =(((params[:item][:days].to_i * 24)+params[:item][:hours].to_i)*60+params[:item][:minutes].to_i)*60
     @auction = Auction.create(:item_id =&gt; @item.id, :highest_bid_id =&gt; 0, :exp_time =&gt;          @item.created_at+ @elapsed_seconds.seconds, :suspend =&gt; 0, :user_id =&gt; @current_user.id, :extend_bit =&gt; 0 )
     @item.update_attributes(:auction_id =&gt; @auction.id)
     @item_id = @item.id
     @auction_id = @auction.id
     @t1 = Thread.new{
     @timer = Timers.new
     @bid_timer = @timer.after(@elapsed_seconds){
     if Auction.find_by_id(@auction_id).suspend != 1
         buy
     end
      }
     @timer.wait
    }
   end
  
   # PUT /items/1
   # PUT /items/1.json
   def update
     @item = Item.find(params[:id])
  
     respond_to do |format|
  
     if @item.update_attributes(params[:item])
       format.html { redirect_to @item, notice: 'Item was successfully updated.' }
       format.json { head :no_content }
     else
       format.html { render action: "edit" }
       format.json { render json: @item.errors, status: :unprocessable_entity }
     end
    end
   end
  
   # DELETE /items/1
   # DELETE /items/1.json
   def destroy
     @item = Item.find(params[:id])
     @item.destroy
  
     respond_to do |format|
       format.html { redirect_to items_url }
       format.json { head :no_content }
     end
   end 
  end
  </code></pre>
  
  <p>I would like to have someone's advice. Thank you in advance.</p>