I'm having a bit of trouble writing rspec tests for controller actions that only respond to js.
Example Controller action:
def create
@user = user.new(user_params)
respond_to do |format|
if user.save
format.js
end
end
end
Here's some rspec I would write if the controller action responded to html:
context 'with valid attributes' do
it 'creates a new user' do
expect {
post :create, user: build(:user)
}.to change(User,:count).by(1)
end
I am trying to figure out how to write a similar test but make it work with the format js.
Thanks!
Use this xhr :post, :create, user: build(:user)
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