Rails - Rspec 3 controller action with format.js
rspec, ruby-on-rails, ruby-on-rails-4
Solution
Use this `xhr :post, :create, user: build(:user)`
Problem
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!