根据be
matchers文档,如果为真(不是或) ,expect(obj).to be
则此测试通过。obj
nil
false
expect(decoded_response['entity']['guid']).to be
表示如文档所述,如果值为decoded_response['entity']['guid']
任何对象,但不是nil
or false
,则测试将通过。
这是一个演示示例:
RSpec.describe "be matcher" do
context "when object is truthy" do
specify { expect(2).to be }
end
context "when object is not truthy" do
specify { expect(nil).not_to be }
end
end
让我们运行这个测试:-
[arup@Ruby]$ rspec --format d spec/a_spec.rb
be matcher
when object is truthy
should be
when object is not truthy
should not be
Finished in 0.00254 seconds (files took 0.42175 seconds to load)
2 examples, 0 failures