Module: BeanCounter::TestAssertions
- Defined in:
- lib/bean_counter/test_assertions.rb
Instance Method Summary collapse
-
#assert_enqueued(options = {}) ⇒ true
Asserts that some number of jobs are enqueued that match the given Hash of
options
. -
#assert_enqueues(options = {}) { ... } ⇒ true
Asserts that the provided
block
enqueues some number of jobs that match the given Hash ofoptions
. -
#assert_tube(options = {}) ⇒ true
Asserts that at least one tube exist that matches the given Hash of
options
. -
#enqueue_expectation(assertion_method, options, &block) ⇒ Object
private
Builds job expectation object, evaluates, and makes appropriate assertion with appropriate failure message.
-
#refute_enqueued(options = {}) ⇒ false
Asserts that no jobs are enqueued that match the given Hash of
options
. -
#refute_enqueues(options = {}) { ... } ⇒ false
Asserts that the given
block
enqueues no jobs that match the given Hash ofoptions
. -
#refute_tube(options = {}) ⇒ false
Asserts that no tube exist that matches the given Hash of
options
. -
#tube_expectation(assertion_method, message_type, options) ⇒ Object
private
Builds tube expectation object, evaluates, and makes appropriate assertion with appropriate failure message.
Instance Method Details
#assert_enqueued(options = {}) ⇒ true
Asserts that some number of jobs are enqueued that match the given Hash of
options
. If no options
are given, asserts that at least one job exists.
Each key
in options
is a String or a Symbol that identifies an attribute
of a job that the corresponding value
should be compared against. All attribute
comparisons are performed using the triple-equal (===) operator/method of
the given value
.
options
may additionally include a count
key ('count' or :count) that
can be used to assert that a particular number of matching jobs are found.
If no count
option is provided, the assertion succeeds if any job is found
that matches all of the options
given. If no jobs are found that match the
options
given, the assertion fails.
If a count
option is provided the assertion only succeeds if the triple-equal
(===) operator/method of the value of count
evaluates to true when given the
total number of matching jobs. Otherwise the assertion fails. The use of ===
allows for more advanced comparisons using Procs, Ranges, Regexps, etc.
See Strategy::MATCHABLE_JOB_ATTRIBUTES for a list of what attributes can be used when matching.
See Strategy#job_matches? and/or the #job_matches? method of
the strategy in use for more detailed information on how it is determined
whether or not a job matches the given options
.
44 45 46 |
# File 'lib/bean_counter/test_assertions.rb', line 44 def assert_enqueued( = {}) enqueue_expectation(:assert, ) end |
#assert_enqueues(options = {}) { ... } ⇒ true
Asserts that the provided block
enqueues some number of jobs that match
the given Hash of options
. If no options
are given, asserts that at
least one job is enqueued during the execution of the block
.
Unlike #assert_enqueued, which will evaluate all jobs in the Beanstalkd pool,
this method will only evaluate jobs that were enqueued during the
execution of the given block
. This can be useful for performance and for
making assertions that could return false positives if all jobs were
evaluated.
Each key
in options
is a String or a Symbol that identifies an attribute
of a job that the corresponding value
should be compared against. All attribute
comparisons are performed using the triple-equal (===) operator/method of
the given value
.
options
may additionally include a count
key ('count' or :count) that
can be used to assert that a particular number of matching jobs are found.
If no count
option is provided, the assertion succeeds if any job is found
that matches all of the options
given. If no jobs are found that match the
options
given, the assertion fails.
If a count
option is provided the assertion only succeeds if the triple-equal
(===) operator/method of the value of count
evaluates to true when given the
total number of matching jobs. Otherwise the assertion fails. The use of ===
allows for more advanced comparisons using Procs, Ranges, Regexps, etc.
See Strategy::MATCHABLE_JOB_ATTRIBUTES for a list of what attributes can be used when matching.
See Strategy#job_matches? and/or the #job_matches? method of
the strategy in use for more detailed information on how it is determined
whether or not a job matches the given options
.
97 98 99 100 101 |
# File 'lib/bean_counter/test_assertions.rb', line 97 def assert_enqueues( = {}) raise ArgumentError, 'Block required' unless block_given? enqueue_expectation(:assert, , &Proc.new) end |
#assert_tube(options = {}) ⇒ true
Asserts that at least one tube exist that matches the given Hash of
options
. If no options
are given, asserts that at least one tube exists,
which will always succeed.
Each key
in options
is a String or a Symbol that identifies an attribute
of a tube that the corresponding value
should be compared against. All attribute
comparisons are performed using the triple-equal (===) operator/method of
the given value
.
The assertion succeeds if any tube exists that matches all of the given
options
. If no tube exists matching all of the given options
, the assertion
fails.
See Strategy::MATCHABLE_TUBE_ATTRIBUTES for a list of those attributes that can be used when matching.
See Strategy#tube_matches? and/or the #tube_matches? method of
the strategy in use for more detailed information on how it is determined
whether or not a tube matches the given options
.
135 136 137 |
# File 'lib/bean_counter/test_assertions.rb', line 135 def assert_tube( = {}) tube_expectation(:assert, :failure_message, ) end |
#enqueue_expectation(assertion_method, options, &block) ⇒ Object (private)
Builds job expectation object, evaluates, and makes appropriate assertion with appropriate failure message.
261 262 263 264 265 266 |
# File 'lib/bean_counter/test_assertions.rb', line 261 def enqueue_expectation(assertion_method, , &block) = assertion_method == :assert ? :failure_message : :negative_failure_message expectation = BeanCounter::EnqueuedExpectation.new() match = expectation.matches?(block_given? ? block : nil) send(assertion_method, match, expectation.send()) end |
#refute_enqueued(options = {}) ⇒ false
Asserts that no jobs are enqueued that match the given Hash of options
.
If no options
are given, asserts that no jobs exist.
Each key
in options
is a String or a Symbol that identifies an attribute
of a job that the corresponding value
should be compared against. All attribute
comparisons are performed using the triple-equal (===) operator/method of
the given value
.
The refutation succeeds if no jobs are found that match all of the options
given. If any matching jobs are found, the refutation fails.
See Strategy::MATCHABLE_JOB_ATTRIBUTES for a list of what attributes can be used when matching.
See Strategy#job_matches? and/or the #job_matches? method of
the strategy in use for more detailed information on how it is determined
whether or not a job matches the given options
.
170 171 172 |
# File 'lib/bean_counter/test_assertions.rb', line 170 def refute_enqueued( = {}) enqueue_expectation(:refute, ) end |
#refute_enqueues(options = {}) { ... } ⇒ false
Asserts that the given block
enqueues no jobs that match the given Hash
of options
. If no options
are given, asserts that no job are enqueued
by the given block
.
Unlike #refute_enqueued, which will evaluate all jobs in the beanstalkd pool,
this method will only evaluate jobs that were enqueued during the
execution of the given block
. This can be useful for performance and for
making assertions that could return false positives if all jobs were
evaluated.
Each key
in options
is a String or a Symbol that identifies an attribute
of a job that the corresponding value
should be compared against. All attribute
comparisons are performed using the triple-equal (===) operator/method of
the given value
.
The refutation succeeds if no jobs are found that match all of the options
given. If any matching jobs are found, the refutation fails.
See Strategy::MATCHABLE_JOB_ATTRIBUTES for a list of what attributes can be used when matching.
See Strategy#job_matches? and/or the #job_matches? method of
the strategy in use for more detailed information on how it is determined
whether or not a job matches the given options
.
211 212 213 214 215 |
# File 'lib/bean_counter/test_assertions.rb', line 211 def refute_enqueues( = {}) raise ArgumentError, 'Block required' unless block_given? enqueue_expectation(:refute, , &Proc.new) end |
#refute_tube(options = {}) ⇒ false
Asserts that no tube exist that matches the given Hash of options
.
If no options are given, asserts that no tubes exist which will always fail.
Each key
in options
is a String or a Symbol that identifies an attribute
of a tube that the corresponding value
should be compared against. All attribute
comparisons are performed using the triple-equal (===) operator/method of
the given value
.
The refutation succeeds if no tube exists that matches all of the given
options
. If any tubes exist that match all of the given options
, the
refutation fails.
See Strategy::MATCHABLE_TUBE_ATTRIBUTES for a list of those attributes that can be used when matching.
See Strategy#tube_matches? and/or the #tube_matches? method of the strategy
in use for more detailed information on how it is determined whether or not
a tube matches the given options
.
252 253 254 |
# File 'lib/bean_counter/test_assertions.rb', line 252 def refute_tube( = {}) tube_expectation(:refute, :negative_failure_message, ) end |
#tube_expectation(assertion_method, message_type, options) ⇒ Object (private)
Builds tube expectation object, evaluates, and makes appropriate assertion with appropriate failure message.
271 272 273 274 275 |
# File 'lib/bean_counter/test_assertions.rb', line 271 def tube_expectation(assertion_method, , ) expectation = BeanCounter::TubeExpectation.new() match = expectation.matches? send(assertion_method, match, expectation.send()) end |