开发者

undefined method `it' for main:Object (NoMethodError) Rspec

开发者 https://www.devze.com 2023-04-02 00:03 出处:网络
Writing a rspec test to check the association is valid. My code follows Model class Comment < ActiveRecord::Base

Writing a rspec test to check the association is valid. My code follows

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 

I don't have any validation, and don't really need to test anything apart from the association. I get the following error:

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

I have an undefined method 'it' I don't seem to understand how I can declare this?


Your it block isn't in a describe block. Try the following:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消