Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 282 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to put assertions in ruby code

#1
I want to use the assertions and put valuidations in my ruby code (e.g: checking if a zip file is created, label is present, message in the text area, etc). I have put a few assert statements like `assert @selenium.is_text_present(textMessage)`, but they don't work.

Please let me know if any ruby gem for assertions is to be installed.
Reply

#2
If you're just developing or debugging and need a quick one-liner

`throw 'Error message' unless thing == expected`
Reply

#3
Use the [**solid_assert**](

[To see links please register here]

) gem to add assertions to Ruby.

**See:**
[solid_assert: A simple Ruby assertion
utility](

[To see links please register here]

)
[Is it idiomatic Ruby to add an assert( ) method to Ruby's Kernel
class?](

[To see links please register here]

)
Reply

#4
For simple asserts, you're probably best off rolling your own assert method taking a block:

ruby-1.9.1-p378 > class AssertionError < RuntimeError
ruby-1.9.1-p378 ?> end
=> nil
ruby-1.9.1-p378 > def assert &block
ruby-1.9.1-p378 ?> raise AssertionError unless yield
ruby-1.9.1-p378 ?> end
=> nil
ruby-1.9.1-p378 > assert { 1 > 0 }
=> nil
ruby-1.9.1-p378 > assert { 5 == 12 }
AssertionError: AssertionError
from (irb):8:in `assert'
from (irb):11
from /Users/mr/.rvm/rubies/ruby-1.9.1-p378/bin/irb:17:in `<main>'

In copypastastable form:

class AssertionError < RuntimeError
end

def assert &block
raise AssertionError unless yield
end

i = 1
assert {i >= 0}
assert { 5 == 12 }

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through