首页 文章

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

提问于
浏览
0

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

Model

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 回答

  • 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
    

相关问题