RSpec中使用多个'简单”expectation的最佳实践格式通常是将每个expectation放在一个单独的it块中。这样可以更好地组织和可读代码。
describe Class do
subject { Class.new }
it "has a default value of 0 for an instance variable" do
expect(subject.instance_variable).to eq 0
end
it "increases the instance variable when called" do
subject.method_that_increases_instance_variable
expect(subject.instance_variable).to eq 1
end
it "decreases the instance variable when called" do
subject.method_that_decreases_instance_variable
expect(subject.instance_variable).to eq -1
end
end