mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
5b44edf8b3
Currently, using `ensure_inclusion_of` against a boolean column doesn't work. We can assert that the column allows boolean values, but what about values that should be rejected? Well, it depends on what you give to `ensure_inclusion_of`. Here's how it works now: * `ensure_inclusion_of(:attr).in_array([true])` asserts that false is rejected * `ensure_inclusion_of(:attr).in_array([false])` asserts that true is rejected * `ensure_inclusion_of(:attr).in_array([true, false])` does not assert that anything is rejected, instead informing the developer how this sort of expectation is not fully testable (anything other than true, false, or nil will be converted to false). * `ensure_inclusion_of(:attr).in_array([nil])`, when the column is nullable, does not assert that anything is rejected, either, also printing a warning * `ensure_inclusion_of(:attr).in_array([nil])`, when the column is non-nullable, raises an error because this expectation is not testable in any way, as setting a boolean column to nil this way will get converted to false.
19 lines
425 B
Ruby
19 lines
425 B
Ruby
module Kernel
|
|
unless method_defined?(:capture)
|
|
def capture(stream)
|
|
stream = stream.to_s
|
|
captured_stream = Tempfile.new(stream)
|
|
stream_io = eval("$#{stream}")
|
|
origin_stream = stream_io.dup
|
|
stream_io.reopen(captured_stream)
|
|
|
|
yield
|
|
|
|
stream_io.rewind
|
|
return captured_stream.read
|
|
ensure
|
|
captured_stream.unlink
|
|
stream_io.reopen(origin_stream)
|
|
end
|
|
end
|
|
end
|