用户没有响应rspec中的方法-User失败/错误:它{should respond_to(:method)}

时间:2013-06-25 16:09:46

标签: ruby-on-rails ruby rspec devise

我没有通过Rspec测试,我无法确定我做错了什么。

这是我的用户规范

require 'spec_helper'

describe User do
   before do
     @user = User.new(name: "Example User", email: "user@example.com",
          password: "foobar", password_confirmation: "foobar")
   end

   subject { @user }

   it { should respond_to(:courses)}
   it { should respond_to(:take_course!)} # this test fails
   it { should respond_to(:taking_course?)} # this test fails as well

end

这是我的user.rb文件

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me
  has_many :assignments, foreign_key: "user_id", dependent: :destroy
  has_many :courses, through: :assignments

  def take_course!
  end

  def taking_course?
  end
end

我还没有在方法中有任何东西,但我很困惑为什么它没有回应它。

1 个答案:

答案 0 :(得分:0)

正如Vimsha指出的那样 - 我使用Spork作为测试预加载器,只需重新启动Spork。