Unit Rails - How To Assert One Number Is Greater Than Another One?
Maybe your like
Tags:
assert
ruby-on-rails
testunit
I am writing my first unit tests with Test::Unit and I have reached a point where I need to compare two numbers. Much to my surprise, I have discovered that none of the following were available:
assert_greater_than assert_lesser_than assert_greater_or_equal_than assert_lesser_or_equal_thanIs this normal? How should I do it then?
Thanks
Amokrane Chentir
3 Answers
Rather than provide a bunch of different assertions as you suggest, Test::Unit provides the method assert_operator, used like this:
assert_operator x, :>, y assert_operator x, :>=, y etc.Jacob Mattison
How about this simple thing,
assert x>y
answered Oct 17 '22 11:10 bragboy
Here are some functions you can put in test/test_helper.rb
def assert_gt(a, b) assert_operator a, :>, b end def assert_gte(a, b) assert_operator a, :>=, b end def assert_lt(a, b) assert_operator a, :<, b end def assert_lte(a, b) assert_operator a, :<=, b endThen call like so:
assert_gt 6, 3 assert_gte 5, 5 assert_lt 4, 5 assert_lte 5, 5Tyler
Sign in to CommentRelated questions
Rails: Sprockets::Rails::Helper::AssetNotPrecompiled in development How can I get the Rails asset pipeline to produce source maps? How would you create a notification system like on SO or Facebook in RoR? Wkhtmltopdf Characters in single line partially cut between pages Circular dependency detected while autoloading constant when loading constant LDAP through Ruby or Rails Filter to execute before render but after controller? create custom html helpers in ruby on rails How to set the ActionMailer default_url_options's :host dynamically to the request's hostname? How to detect what causes a deprecation warning in Rake Active Record has_many :through remove one associated record Passing variables inside rails internationalization yml file How do I get an ENV variable set for rspec? cannot load railtie after upgrade to rails 4 per ruby.railstutorial.org What does binding a Rails Server to 0.0.0.0 buy you? Do I have to manually uninstall all dependent gems? Rails Associations - has_many => :through - but same model Strong parameters require multiple Inline ruby in :javascript haml tag? [duplicate] Rails Devise: Set password reset token and redirect userRecent Activity
- how to turn off autocomplete for an input in html? [duplicate]
- Distributed database, many lightly loaded nodes
- Send traces to DataDog agentless with SpringBoot3 micrometer
- bash Script to replace words
- VSCode Dart & Flutter unusably slow on MacOS
- JavaFX scene minWidth and minHeight not working
Donate For Us
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us WithTag » How To Check For Value Greater Than 1 In Ruby
-
Ruby How To Find Each Value In Hash Greater Than X? - Stack Overflow
-
Ruby Comparison Operators - W3resource
-
Ruby How To Find Each Value In Hash Greater Than X? - Appsloveworld
-
List And Hash Formulas | Workato Docs
-
Class: Numeric (Ruby 2.5.0)
-
Class: Range (Ruby 2.5.1)
-
Comparison Operators - Ruby For Beginners
-
Loops In Ruby - Performing Repeated Operations On A Data Set
-
Elements Greater Than The Previous And Next Element In An Array
-
Query An Array — MongoDB Manual
-
Python | Check If All The Values In A List That Are Greater Than A Given ...
-
The Beginners Guide To Ruby If & Else Statements - RubyGuides
-
Expressions And Operators - Puppet
-
Class Integer - Documentation For Ruby 2.4.0