Is there a better way to format this test to make it more readable?
expect {
within '.foo' do
click_link 'Delete'
end
}.to change {Foo.count}.by 1
expect do...end
works, but is even uglier...
Maybe something like this?
expected = expect do
within '.foo' do
click_link 'Delete'
end
end
expected.to change { Foo.count }.by 1
Not exactly pretty, but reduces some of the line noise.
Since putting everything in curly braces and on one line would be too long, I'd write it like this:
expect do
within(".foo") { click_link "Delete" }
end.to change { Foo.count }.by 1
Update: Not tested, but this should work too:
click_delete_link = lambda { within(".foo") { click_link "Delete" } }
expect { click_delete_link }.to change { Foo.count }.by 1
But I still like the first version better :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With