【问题标题】:RSpec giving an error on every action in controller?RSpec 对控制器中的每个操作都给出错误?
【发布时间】:2012-06-03 06:56:56
【问题描述】:

这很奇怪,我在我的 rails 应用程序上运行bundle exec guard,并且在一个单独的容器中的每个操作都得到一长串错误。所有的错误都是完全相同的,没有任何意义,这就是我对所有操作的结果:

1) PriceProfilesController GET index assigns all price_profiles as @price_profiles
     Failure/Error: Unable to find matching line from backtrace
     ArgumentError:
       wrong number of arguments (1 for 0)
     # ./app/controllers/price_profiles_controller.rb:15:in `extend'

  2) PriceProfilesController GET show assigns the requested price_profile as @price_profile
     Failure/Error: Unable to find matching line from backtrace
     ArgumentError:
       wrong number of arguments (1 for 0)
     # ./app/controllers/price_profiles_controller.rb:15:in `extend'

... and so forth

知道发生了什么吗? PriceProfileContainer 几乎是一个标准的脚手架。我应该在哪里看这里。规范文件由脚手架自动生成。

更新----

这是我的控制器代码中的扩展功能:

# GET /price_profiles/1/extend
  def extend
    @price_profile = PriceProfile.find(params[:id])
    @products = Product.all()
    @locations = Location.all()
    @price_profile_date_range = PriceProfileDateRange.new()

    #respond_to do |format|
    #  format.html # extend.html.erb      
    #end
  end

差不多了。

【问题讨论】:

  • 我认为您需要发布您的控制器代码。根据该错误,您似乎在 price_profiles_controller 中调用了第 15 行的 extend 方法并将其传递给它不期望的参数。但需要查看代码才能确定。
  • @GeoffLanotte 嗨,请查看我的更新

标签: ruby-on-rails-3 rspec tdd


【解决方案1】:

extend 是一个核心 ruby​​ 方法,允许您将模块的方法添加到对象(有点像包含)

有些东西(你可以通过查看回溯的其余部分来判断)试图在你的控制器实例上调用 extend,期望核心 ruby​​ 的 extend 方法,它需要 1 个参数),而是找到你的 extend 方法,它需要没有参数(当然做一些完全不同的事情)。

最简单的方法是为您的方法选择一个不同的名称

【讨论】:

  • 哎呀——但作为一个应用程序,它在浏览器中运行得非常好。我会进行更改并检查。
  • rspec 扩展您的控制器以执行一些测试魔法
  • 宾果游戏!正是这里的问题,一个简单的重命名和 rspecs 很高兴 - 非常感谢,我几乎在我的智慧结束这里。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多