Reputation: 15216
I have a trouble with rspec 2.14 syntax. RSpec controller work good, but it require different syntax.
describe Frontend::UsersController, type: :controller do
describe 'POST "create"' do
subject { post :create, user: { login: email } }
context 'with valid attributes' do
let(:email) { FactoryGirl.attributes_for(:user)[:email] }
it { expect{ subject }.to change{ User.count }.by(1) }
it { expect(subject).to redirect_to(root_path) }
Why change and redirect methods requires different syntax?
Upvotes: 1
Views: 97
Reputation: 3627
They don't. You could do change(User, :count)
instead. The form you're using evaluates the block before and after running that line and checks if the value changed appropriately. In English:
create
in the Frontend::UsersController
.UPDATE
In case you're actually talking about expect{subject}
vs. expect(subject)
: the change
expectation needs something to test for change against. Since you're passing expect
a block, change
knows it can first check the User count, evaluate the block (call subject
), then check the User count again. If you didn't pass a block, it's ambiguous for when you'd actually want to start checking for changes in the User count.
Upvotes: 1