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
精彩评论