Last active
June 12, 2018 22:04
-
-
Save alebian/14d9ff254caab6b3e2de7200e4e767ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/expectations' | |
RSpec::Matchers.define :match_stream do |expected_stream| | |
match do |actual_stream| | |
loop do | |
actual_element = actual_stream.next rescue :eof | |
expected_element = expected_stream.next rescue :eof | |
return false unless actual_element == expected_element | |
return true if actual_element == :eof | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expected_enum = some_array_or_file.each.lazy # or some other of enum | |
it 'returns an enum with the values' do | |
expect(subject.call).to match_stream(expected_enum) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment