I am testing my model
method which returns me an Account object
. I am checking whether my table has inserted a new row
and my Model reflects its count.
Below is my spec.
it "can create an account" do
create_account = Account.create(account: acc)
create_account.should change(Account, :count).by(1);
end
Error i am getting
8) Account can create an account
Failure/Error: create_account.should change(Account, :count).by(1);
expected #count to have changed by 1, but was not given a block
to look forward to; regard as likely to happen; anticipate the occurrence or the coming of: I expect to read it. I expect him later. She expects that they will come. to look for with reason or justification:We expect obedience. Informal. to suppose or surmise; guess: I expect that you are tired from the trip.
Synonyms for expected. anticipated, awaited, hoped (for), watched (for)
1. to regard as probable or likely; anticipate: he expects to win. 2. to look forward to or be waiting for: we expect good news today. 3. to decide that (something) is requisite or necessary; require: the boss expects us to work late today.
The difference is simply that What do you expect to know? poses a question in the "active" voice (for which the answer might be I expect to know X). By contrast, What are you expected to know? is "passive" (a typical answer being I am expected to know X).
The #change
matcher expects a block in which some action is performed that effects the expected change. Try this:
expect { Account.create(account: acc) }.to change{ Account.count }.by(1)
See https://www.relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/expect-change
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