源码如下:
$ cat spec/nested_subject_spec.rb
class ArrayWithOneElement < Array
def initialize(*)
super
unshift "first element"
end
end
describe Array do
describe ArrayWithOneElement do
context "referenced as subject" do
it "contains one element" do
expect(subject).to include("first element")
end
end
end
end
下面是执行结果:
$ rspec spec/nested_subject_spec.rb
F
Failures:
1) Array ArrayWithOneElement referenced as subject contains one element
Failure/Error: expect(subject).to include("first element")
expected [] to include "first element"
# ./spec/nested_subject_spec.rb:12:in `block (4 levels) in <top (required)>'
Finished in 0.00099 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/nested_subject_spec.rb:11 # Array ArrayWithOneElement referenced as subject contains one element
官方网站上也说应该是 pass 的,但我执行就 fail 了,不得其解