有没有更好的方法来格式化这个测试以使其更具可读性?
expect {
within '.foo' do
click_link 'Delete'
end
}.to change {Foo.count}.by 1
期望do...end
有效,但更丑陋...
有没有更好的方法来格式化这个测试以使其更具可读性?
expect {
within '.foo' do
click_link 'Delete'
end
}.to change {Foo.count}.by 1
期望do...end
有效,但更丑陋...
也许是这样的?
expected = expect do
within '.foo' do
click_link 'Delete'
end
end
expected.to change { Foo.count }.by 1
不完全漂亮,但减少了一些线路噪音。
由于将所有内容放在花括号中并放在一行上会太长,所以我会这样写:
expect do
within(".foo") { click_link "Delete" }
end.to change { Foo.count }.by 1
更新:未经测试,但这也应该有效:
click_delete_link = lambda { within(".foo") { click_link "Delete" } }
expect { click_delete_link }.to change { Foo.count }.by 1
但我还是更喜欢第一个版本:)