2017-06-22 62 views
0

更新:這實際上工作正常。請忽略此問題如何在RSpec請求規範中運行調試器?

我已經習慣了能夠打電話byebug在一個RSpec控制器測試,但這並沒有在一個RSpec request spec ....它不會產生錯誤,但它也沒有按」沒有任何作用。請求規格中是否有其他方式放入調試器?

如:

# spec/controllers/users_controller_spec.rb 
require 'rails_helper' 
describe UsersController do 
    describe "GET #index logged out" do 
    it "returns 401 when not logged in" do 
     get :index, format: :json_api 
     expect(response).to have_http_status(401) 
     byebug 
    end 
    end 
end 

以上下降到調試器,下面沒有:

# specs/requests/users_request_spec.rb 
require 'rails_helper' 
describe "users", type: :request do 
    describe 'GET /users logged out' do 
    it 'returns 401 when not logged in' do 
     get '/users' 
     expect(response).to have_http_status(401) 
     byebug 
    end 
    end 
end 

回答

1

我已經測試您的文件在我的環境

# specs/requests/users_request_spec.rb 
require 'rails_helper' 
describe "companies", type: :request do 
    describe 'GET /companies logged out' do 
    it 'returns 401 when not logged in' do 
     binding.pry # => this stops execution 
     get '/companies.json_api' 
     expect(response).to have_http_status(401) 
     binding.pry # => this does not 
    end 
    end 
end 

理由讓我:

Failure/Error: get '/companies.json_api' 

    ActionController::RoutingError: 
     No route matches [GET] "/companies.json_api" 
    # ./spec/requests/users_request_spec.rb:6:in `block (3 levels) in <top (required)>' 

爲了達到調試器,應該沒有例外。你確定這與你一樣嗎?

+0

@simon你能讓我知道這是否有效? – gates

+1

感謝您的測試。對不起,我應該有'/ users'而不是'/ companies.json_api'。我編輯了這個問題。 –

+0

感謝您對此進行測試!我錯了,所以我會更新它來說。我會接受你的回答。 –

相關問題