Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use expect to test for less than

Tags:

ruby

rspec

Relish suggests the following...

expect(actual).to be <  expected

However if I try...

 x.rand(10)
 expect(x).to be < 11 

full spec

Then(/^I find each world produces just up to (\d+) fighters per turn and no higher$/) do |arg1|
    test = Planet.new
    test.production.each_index do |ndx|
       expect(test.production[ndx]).to be < 11
    end
  end

I'll get

undefined method `<' for #<RSpec::Matchers::BuiltIn::BePredicate:0x0000000268a3b0> (NoMethodError)

What is the current proper syntax to use expect in a less than comparison?

like image 377
TangibleDream Avatar asked Oct 26 '25 03:10

TangibleDream


1 Answers

Syntax looks good. I would first make a very small simple spec, independent of your code to see if your setup works. For example (it should fail btw ;):

describe 'test' do
  it 'works' do
    expect(2).to be < 1
  end
end
like image 87
Axe Avatar answered Oct 28 '25 03:10

Axe