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

Dav*_*vid 0 ruby rspec ruby-on-rails ruby-on-rails-3

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

模型

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

end
Run Code Online (Sandbox Code Playgroud)

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 
Run Code Online (Sandbox Code Playgroud)

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

 `<top (required)>': undefined method `it' for main:Object (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

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

luc*_*tte 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
Run Code Online (Sandbox Code Playgroud)