Since putting everything in curly braces and on one line would be too long, I would write it as follows:
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 :)
source share