【发布时间】:2015-03-26 06:25:36
【问题描述】:
我无法理解为什么以下 Rspec 测试没有通过 -
require "rspec"
require_relative "file-to-be-tested"
describe Customer do
it "is valid with firstname" do
customer = Customer.new("handy")
expect(customer).to be_valid
end
end
对应的类定义——
class Customer
attr_reader :firstname
def initialize(firstname)
@firstname = firstname
end
end
这两个代码 sn-ps 位于同一文件夹中的不同文件中,所以当我在终端中运行 ~rspec <first-filename> 时,我收到以下错误 -
F
Failures:
1) Customer is valid with firstname
Failure/Error: expect(customer).to be_valid
expected #<Customer:0x007f90e50f3110> to respond to `valid?`
# ./poodr/poodr_rspec.rb:8:in `block (2 levels) in <top (required)>'
Finished in 0.00551 seconds (files took 0.52876 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./poodr/poodr_rspec.rb:6 # Customer is valid with firstname
【问题讨论】: