0
私は、ロボットメソッドを持つPagesControllerを持っています。Rails Rspec予期しない応答テキスト - 一致しない
class PagesController < ApplicationController
...
def robots
respond_to :text
expires_in 6.hours, public: true
end
...
end
マッチングビュー:robots.text.erb
<% if !ENVied.BLOCK_ROBOTS %>
User-agent: *
Disallow:
<% else %>
User-agent: *
Disallow:/
<% end %>
手で試験した場合、これは期待通りに働いているが、しかし、私はいくつかの問題のテストを書いを持っています。..
RSpec.describe PagesController, type: :controller do
...
describe "Staging, Test and Development environments" do
it "should generate a robots.txt that disallows access to everything." do
ENV['BLOCK_ROBOTS']='true'
get :robots, params: {format: "text"}
expect(response.header['Content-Type']).to include 'text/plain'
expect(response.body).to eq("User-Agent: * Disallow: /")
end
end
...
end
予想される出力は次のようになります。
User-agent: *
Disallow:
しかし、返されるエラーは次のとおりです。
Failure/Error: expect(response.body).to eq("User-Agent: * Disallow: /")
expected: "User-Agent: * Disallow: /"
got: ""
(compared using ==)
が第二期待文をコメントアウトし、唯一
expect(response.header…
文が渡されました。
手動で/robots.txtに移動することで目的の結果が得られますので、2番目のexpect文に問題があると思います。
ガイダンスをいただければ幸いです。
Railsの5 ルビー2.3.1
gem 'rspec-rails', '3.5.2'