Closed
Description
I discovered that when using stub_request(...).to_rack
with open-uri
causes the resulting StringIO
object to not contain the status message (ex: "OK"
), and only the status code (ex: "200"
).
Example
require 'rspec' require 'webmock/rspec' require 'rack' require 'robots' describe Robots do let(:robots_txt) do [ 'User-Agent: *', 'Disallow: /' ].join($/) end let(:root_uri) { 'http://example.com' } let(:rack_app) do proc { |env| if env['PATH_INFO'] == '/robots.txt' [200, {'Conten-Type' => 'text/plain'}, [robots_txt]] else [200, {'Conten-Type' => 'text/html'}, ['hello']] end } end before do stub_request(:get, "#{root_uri}/robots.txt").to_rack(rack_app) end let(:user_agent) { 'Ruby' } subject do described_class.get_robots_txt("#{root_uri}/", user_agent) end it "StringIO#status should contain 'OK'" do expect(subject.status).to be == ['200', 'OK'] end end
Output
Failures: 1) Robots StringIO#status should contain 'OK' Failure/Error: expect(subject.status).to be == ['200', 'OK'] expected: == ["200", "OK"] got: ["200", ""] # ./spec/robots_spec.rb:37:in `block (2 levels) in '
Metadata
Assignees
Labels
No labels
Activity