I'm new to testing and tried to test a simple get-Request to this Controller-Method:
def new
u = User.new({firstname: 'John',lastname: 'Smith'})
u.save
end
When i request this method through the browser a new User gets created.
Now i tried to test this get request:
require 'spec_helper'
describe UsersController, :type => :controller do
describe 'GET #new' do
it "generates a fake User" do
expect {get :new}.to change(User, :count).by(1)
end
end
end
But somehow this test fails i get the message:
expected #count to have changed by 1, but was changed by 0
What do i wrong? Thanks