Skip to content

Instantly share code, notes, and snippets.

@alebian
Last active June 12, 2018 22:04
Show Gist options
  • Save alebian/14d9ff254caab6b3e2de7200e4e767ae to your computer and use it in GitHub Desktop.
Save alebian/14d9ff254caab6b3e2de7200e4e767ae to your computer and use it in GitHub Desktop.
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
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