4

I want to test that application responds with 404 error and have code:

require 'spec_helper'

describe Admin::UsersController do

  describe "GET new" do
    before { get :new }
    it { should respond_with(404) }
  end
end

My routes:

namespace :admin, module: :admin do
  resources :users, except: [:new, :create]
end

When I ran local server in production mode it really responds with 404 error, but when I run rspec test, it gives me the following:

1) Admin::UsersController GET new shold not be successful
   Failure/Error: get :new
   ActionController::UrlGenerationError:
     No route matches {:action=>"new", :controller=>"admin/users"}
   # ./spec/controllers/admin_users_spec.rb:7:in `block (3 levels) in <top (required)>'

How can I test this correctly?

Updated with correct answer:

describe "GET new" do
  it "should not route to new" do
    expect(get: :new).not_to be_routable
  end
end
kovpack
  • 4,905
  • 8
  • 38
  • 55
  • 1
    possible duplicate of [Testing error pages in Rails with Rspec + Capybara](http://stackoverflow.com/questions/13996259/testing-error-pages-in-rails-with-rspec-capybara) –  May 24 '14 at 11:22
  • That does not help. I've already read that. No difference. – kovpack May 24 '14 at 11:31

1 Answers1

4

I think you can check it with helper { get :new }.should_not be_routable according to this

Update from comment:

Should be expect(:get => :new).not_to be_routable

Community
  • 1
  • 1
zishe
  • 10,665
  • 12
  • 64
  • 103
  • 3
    Your version did not work either, but a little bit modified worked perfectly: `expect(:get => :new).not_to be_routable` – kovpack May 24 '14 at 20:24