Alexander Abramovich
Alexander Abramovich

Reputation: 11438

Simple Rspec test fails - for what reason?

Coding one of my first rspec tests. headers == nil prints true, but the next test line headers should be_nil fails. Why?

require 'net/http'

$url_arr = []
$url_arr << ...
$url_arr << ...
$url_arr << ...

module NetHelpers
    def get_headers(uri)
        Net::HTTP.get_response(URI.parse(uri)).get_fields('Set-Cookie')
    end
end

describe "new script" do
    include NetHelpers

    $url_arr.each do |uri|
        it "should not return cookies" do
            headers = get_headers(uri)
            p "==========> #{headers == nil}"
            headers should be_nil
        end
    end
end

Also, the output is

got: "new script" (using ==)

Why "new script" is printed, while headers really contains nil?

Upvotes: 1

Views: 585

Answers (1)

Thilo
Thilo

Reputation: 17735

Try

headers.should be_nil

instead.

Upvotes: 1

Related Questions