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!
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.
I think itโs expected, the docs say:
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) }
end
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.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs