在我的一個控制器規格中獲得了真正奇怪的rspec行爲。Rspec似乎沒有針對正確的控制器
最好說明一下。在RubyMine的,當我設置一個斷點,出現這種情況:
#rspec test
describe Api::V1::UsersController do
let(:user) { FactoryGirl.create(:user) }
describe "#show" do
it "responds successfully" do
get 'show', id: user.id
response.should be_success
end
end
#controller
class Api::V1::UsersController < AuthenticatedController
def show # !!! RubyMine breakpoint will stop execution here !!!
user = User.find(params[:id])
user_hash = User.information(user, current_user)
respond_to do |format|
format.json { render json: user_hash.to_json }
end
end
所以上面按預期工作。
但是,現在這個測試失敗了。
#rspec test
describe UsersController do
let(:user) { FactoryGirl.create(:user, is_admin: false) }
describe "#show" do
it "redirects non-admin" do
get 'index'
response.should redirect_to user_path(user)
end
end
#controller
class UsersController < AuthenticatedController
def index # !!! Breakpoint is never hit !!!
@users = User.all
respond_to do |format|
if current_user.is_admin
format.html
format.json { render json: @users }
else
redirect_to user_path(current_user) and return
end
end
end
By the way, this is the result:
Expected response to be a redirect to <http://test.host/users/625> but was a redirect to <https://test.host/users>
沒有在UsersController中的控制器方法中的我的斷點。但如果我在API :: V1 :: UsersController中設置了斷點,所有控制器方法都會被觸發。
任何指導非常感謝。我真的不知道如何調試。
運行測試時能顯示log/test.log的輸出嗎? – rossta