Take the 2-minute tour ×

I'm running this test on rspec...

it 'get email is successful' do
  get :email
  response.should be_success
  response.should render_template('email')


Where the controller code looks like this..

def email
  respond_to do |format|

On my terminal I'm returning with....

3) PostsController checking to see if response for post email is successful
 Failure/Error: response.should be_success
   expected success? to return true, got false
 # ./spec/controllers/posts_controller_spec.rb:116:in `block (3 levels) in <top    

What am I missing here to make the test work? It has to be something obvious. My view file is titled email.js.erb. This action is meant for an AJAX call.

share|improve this question

2 Answers 2

up vote 3 down vote accepted


xhr :get, :email

your request seems not to take into account the expected response type. In Rspec, this is the way to do it if you want to simulate AJAX (XHR) requests.

share|improve this answer
Thanks. It works. –  jason328 Nov 19 '12 at 21:17

Your controller is structured to return anything only for JS requests and you are requesting HTML response in your tests. You should have

get :email.js

in your spec.

share|improve this answer
If this doesn't work, try get :email, :format => js. –  Jason Noble Nov 19 '12 at 21:06
Both solutions return with undefined method js. –  jason328 Nov 19 '12 at 21:09

Your Answer


