私は次のようなコントローラーメソッドを持っています:
class TestController < ApplicationController
def testAction
render :json => { 'success'=>1 }.to_json
end
end
このアクションをブラウザーにロードすると、期待どおりの結果が得られます。{"success":1}
ただし、RSpecでテストするとresponse.body
、'<html><body>You are being <a href="https://test.host/test/testAction">redirected</a>.</body></html>'
この奇妙なリダイレクトがすべてのコントローラーで発生していることに気づきました。このリダイレクトの発生を停止して、応答本文のチェックを実行するにはどうすればよいですか?
ありがとう!
- - - - - - - - - - - - 編集:
次のテストの失敗が発生している理由はありますか?
# app/controllers/test_controller.rb
def test
flash[:notice] = 'test'
end
# spec/controllers/test_controller_spec.rb
describe TestController, "calling the test() method" do
it "should set the flash notice" do
put :test
flash[:notice].should_not be_blank
end
end
# result
'TestController calling the test() method should set the flash notice' FAILED
expected blank? to return false, got true