unde的方法`it'用于main:Object(NoMethodError)Rspec

时间:2011-08-31 10:54:41

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

编写rspec测试以检查关联是否有效。我的代码如下

型号

class Comment < ActiveRecord::Base
  require 'carrierwave/orm/activerecord'
  mount_uploader :file, FileUploader
  belongs_to :contact
  belongs_to :company

end

Comment_spec

require 'spec_helper'

describe Comment do
  pending "add some examples to (or delete) #{__FILE__}"
end

   it "should relate to comapny" do 
     Comment.reflect_on_association(:company).should_not be_nil
   end 

我没有任何验证,除了关联之外,不需要测试任何东西。我收到以下错误:

 `<top (required)>': undefined method `it' for main:Object (NoMethodError)

我有一个未定义的方法'它'我似乎不明白我怎么能声明这个?

1 个答案:

答案 0 :(得分:5)

您的it阻止不在describe阻止中。请尝试以下方法:

require 'spec_helper'

describe Comment do
  pending "add some examples to (or delete) #{__FILE__}"


   it "should relate to comapny" do 
     Comment.reflect_on_association(:company).should_not be_nil
   end 

end