I have the following test, that checks wether upon creation of task a new Task and TaskConnection(join table between users and tasks) are made. So far I check that with 2 lambda’s and would like to do it in 1 line…
68 it 'can create new task' do
69 lambda do
70 lambda do
71 post :create, :project_id => project,
72 :task => valid_attributes
73 end.should change(Task, :count).by(1)
74 end.should change(TaskConnection, :count).by(1)
75 end
Something like this… Is it possible?
68 it 'can create new task' do
69 lambda do
71 post :create, :project_id => project,
72 :task => valid_attributes
73 end.should change(Task && TaskConnection, :count).by(1 && 1)
75 end
You can’t do it quite as you suggested in your second example, but you could combine them like this:
I don’t really recommend this approach though. While it’s concise, the errors that RSpec reports when there are failures don’t tell you which expectation failed. It just says that one of them didn’t change the way you thought it would.