Reputation: 189
This code is working but I want to check that it's robust/good practice/idiomatic. Background: I'm following Michael Hartl's rails tutorial and I'm working on 8.5 (exercises for chapter 8), decoupling the tests from the implementation.
In user_pages_spec.rb I didn't like the code
expect { click_button submit }.not_to change(User, :count)
Since change(User, :count)
looks like a bit of a hack. So in spec/support/utilities.rb I wrote:
def create_user
change(User, :count)
end
And I replaced the line in user_pages_spec.rb with
expect { click_button submit }.not_to create_user
Was this sensible?
Upvotes: 0
Views: 60
Reputation: 2946
Doing that is pretty much just "wrapping" the syntax, I don't think it really adds much to the code. The code you had earlier wasn't too bad, but perhaps you could also consider doing this:
expect { click_button submit }.to_not change{User.count}
Upvotes: 1