I am trying to figure out another way of writing the should change count test (without lambda). I am using Rails 3. I am also utilizing the shoulda matcher gem
Reason - All test cases are in the format
describe "some stuff" do
it { should ... }
end
But I am not able to follow the same pattern for testing the should change count
Here is what I have
describe "some stuff" do
it "should change count by one" do
lambda { ... }.should change(Model, :count).by(1)
end
end
Is there a way to write it
describe "some stuff" do
it { should change(Model, :count).by(1) }
end
Thanks a lot !!
subject { lambda { ... } }
it { should change(Model, :count).by(1) }
You can also use the expect syntax:
describe "some stuff" do
expect { ... }.to change(Model, :count).by(1)
end
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