小编Tom*_*728的帖子

Rspec - 控制器测试错误 - Paperclip :: AdapterRegistry :: NoHandlerError:找不到"#<File:0x531beb0>"的处理程序

我问我的Rspec测试如下.

Rspec - RuntimeError:nil的被调用id,错误地为4

在相同的代码(Rspec测试"items_controller.rb"),我试图进行"PUT更新"测试.但是我收到错误"Paperclip :: AdapterRegistry :: NoHandlerError:找不到"#"的处理程序.

我的Rspec测试如下.老实说,我猜这个失败的原因是""照片"=> File.new(Rails.root +'app/assets/images/rails.png')"on"let(:valid_attributes)".但是,我尝试了几种方法,但我无法修复.顺便说一句,我的rails版本是"Rails 3.2.14".然后我尝试了以下帖子,但也不能.

无法弄清楚是什么导致我的测试失败

错误如下.

......F....

Failures:

  1) ItemsController PUT update could not update successfully
     Failure/Error: put :update, {:id => item.to_param, :item => valid_attributes}, valid_session
     Paperclip::AdapterRegistry::NoHandlerError:
     No handler found for "#<File:0x5d4c548>"
     # ./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 <top (required)>'

 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 …
Run Code Online (Sandbox Code Playgroud)

ruby testing rspec ruby-on-rails ruby-on-rails-3

5
推荐指数
1
解决办法
5622
查看次数

Rspec 错误 - NoMethodError:未定义的方法“空?”

我现在正在为控制器制作 Rspec SearchController。该控制器使用通过“get”请求获取的参数通过sql搜索记录。控制器如下。

class SearchController < ApplicationController

  def index
    if params[:category] == 'All'
      @search_result = Item.find_by_sql("SELECT * FROM items WHERE name LIKE '%# {params[:name]}%'")
    else
      @search_result = Item.find_by_sql("SELECT * FROM items WHERE name LIKE '%#{params[:name]}%' AND category = '#{params[:category]}'")
    end
    if @search_result.empty? then
      redirect_to main_app.root_path, notice: "No items found matching your search criteria ! Modify your search."
    else
      @search_result=@search_result.paginate(:page => params[:page],:per_page => 3)
    end
  end
 end
Run Code Online (Sandbox Code Playgroud)

然后我编写了简单的 Rspec 测试,如下所示。该测试的目的是首先item使该对象在控制器中使用。Item.stub(:find_by_sql).and_return(item)还声明了存根 ( )。然后get :index用参数做:category …

ruby rspec ruby-on-rails rspec-rails ruby-on-rails-3

0
推荐指数
1
解决办法
2075
查看次数