RSpec未定义的控制器方法AFTER显式控制器声明

时间:2014-01-22 06:37:52

标签: ruby-on-rails ruby rspec

在spec \ controllers \ signups_controller_spec.rb中,我有以下代码

require 'spec_helper'

describe SignupsController, :type => :controller do
  describe "new - it creates a new signup at @signup" do
    get :new
    assigns(:signup).should be_a_new(Signup)
  end
  # ...
end

为了仔细检查复数问题,我的控制器确实是SignupsController。

无论如何,我在其他答案中添加了类型声明,因为我得到了未定义方法'get'的错误,我仍然得到了。有什么想法吗?

C:/Sites/GoogleTest/spec/controllers/signups_controller_spec.rb:6:in `block (2 levels) in <top (required)>': undefined method `get' for #<Class:0x4eaa748> (NoMethodError)

1 个答案:

答案 0 :(得分:0)

这是构建规范的常用方法:

require 'spec_helper'

describe SignupsController, :type => :controller do
  describe "GET new" do
    it "creates a new signup at @signup" do
      get :new
      assigns(:signup).should be_a_new(Signup)
    end
  end

  # ...
end

有关详细信息,请参阅official documentation