Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created August 13, 2010 10:30
Show Gist options
  • Select an option

  • Save lukeredpath/522665 to your computer and use it in GitHub Desktop.

Select an option

Save lukeredpath/522665 to your computer and use it in GitHub Desktop.
# this is just a rough example, the actual nested matcher is irrelevant
Spec::Matchers.define :string_containing do |substring|
match do |actual|
actual.include?(substring)
end
end
results = some_array
results.should include(string_containing("foo"))
# while I'm on the subject, it would be able to reuse the above string_containing matcher for a string directly, but it would need to be named differently to read correctly, i.e.:
"foobar".should contain_string("foo")
# so it would be nice to do:
Spec::Matchers.define :string_containing, :aliases => [:contain_string] do |substring|
match do |actual|
actual.include?(substring)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment