Method: RSpec::Matchers#include

Defined in:
lib/rspec/matchers.rb

#include(*expected) ⇒ Object Also known as: a_collection_including, a_string_including, a_hash_including, including

Passes if actual includes expected. This works for collections and Strings. You can also pass in multiple args and it will only pass if all args are found in collection.

Examples:

expect([1,2,3]).to      include(3)
expect([1,2,3]).to      include(2,3)
expect([1,2,3]).to      include(2,3,4) # fails
expect([1,2,3]).not_to  include(4)
expect("spread").to     include("read")
expect("spread").not_to include("red")
expect(:a => 1, :b => 2).to include(:a)
expect(:a => 1, :b => 2).to include(:a, :b)
expect(:a => 1, :b => 2).to include(:a => 1)
expect(:a => 1, :b => 2).to include(:b => 2, :a => 1)
expect(:a => 1, :b => 2).to include(:c) # fails
expect(:a => 1, :b => 2).not_to include(:a => 2)


639
640
641
# File 'lib/rspec/matchers.rb', line 639

def include(*expected)
  BuiltIn::Include.new(*expected)
end