简体   繁体   中英

Simple Rspec test failure

I have the following model:

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

I am writing a spec test. It goes like this:

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

When I run the spec test I get the following error:

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

This seems like it should very straight forward. Any ideas on why this test fails?

我试图在应该使用nil的地方使用empty。

@shipping_info.should be_nil 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM