我有以下型号:
module CgCart
class ShippingInfo < ActiveRecord::Base
set_table_name 'cg_cart.shipping_infos'
has_many :order, :class_name => "CgCart::Order"
accept_nested_attributes_for :orders, :allow_destroy => true
validates_presence_of :name, :street, :city, :country, :zip, :state
def to_s
retval = <<-formatted_addr
#{self.name}
#{self.street}
#{self.city} #{self.state} #{self.zip}
#{self.country}
formatted_addr
retval.upcase
end
end
end # module
我正在编写规范测试。它是这样的:
require File.dirname(__FILE__) + '/../../spec_helper'
describe CgCart::ShippingInfo do
context "when first created" do
it "should be empty" do
@shipping_info = CgCart::ShippingInfo.new
@shipping_info.should be_empty
end
end
end
当我运行规范测试时,我收到以下错误:
1)
NoMethodError in 'CgCart::ShippingInfo when first created should be empty'
undefined method `be_empty' for #<Spec::Matchers::PositiveOperatorMatcher:0x105f165c0>
./spec/models/cg_cart/shipping_info_spec.rb:6:
Finished in 0.015 seconds
1 example, 1 failure
这似乎应该非常直截了当。关于为什么这个测试失败的任何想法?
答案 0 :(得分:0)
我试图在我应该使用nil的地方使用空。
@shipping_info.should be_nil