Question about test FAIL

Hi folks!
I am a beginner stundent in Ruby and Rspec and I have a question about a test using be_within
Please, take a look the follow screen below.

The error above shou not be occur. Right?
Thanks in advance! :grin:

I think itโ€™s expected, the docs say:

be_within matcher

Note that the difference between the actual and expected values must be smaller than your delta; if it is equal, the matcher will fail.

So you have to write:

it { expect(6.2).to be_within(0.8).of(5.5) }

Which also validates number > 6.2, for example: 6.299999 will also be a valid number.

So I think the appropriate test for you is:

describe 'testa range' do
	it { expect(6.2).to be_between(5.5, 5.5 + 0.7) }

Method: RSpec::Matchers#be_between

The be_within matcher is designed to stop your tests failing due to small floating-point rounding errors. Itโ€™s not really supposed to be used as a range test, and as @SouravGoswami has noted, the be_between matcher is a better choice for your application.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs