File: include_matcher_integration_spec.rb

package info (click to toggle)
ruby-rspec-expectations 2.14.2-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 920 kB
  • sloc: ruby: 8,202; makefile: 4
file content (30 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'spec_helper'

module RSpec
  module Matchers
    describe "include() interaction with built-in matchers" do
      it "works with be_within(delta).of(expected)" do
        expect([10, 20, 30]).to include( be_within(5).of(24) )
        expect([10, 20, 30]).not_to include( be_within(3).of(24) )
      end

      it "works with be_instance_of(klass)" do
        expect(["foo", 123, {:foo => "bar"}]).to include( be_instance_of(Hash) )
        expect(["foo", 123, {:foo => "bar"}]).not_to include( be_instance_of(Range) )
      end

      it "works with be_kind_of(klass)" do
        class StringSubclass < String; end
        class NotHashSubclass; end

        expect([StringSubclass.new("baz")]).to include( be_kind_of(String) )
        expect([NotHashSubclass.new]).not_to include( be_kind_of(Hash) )
      end

      it "works with be_[some predicate]" do
        expect([double("actual", :happy? => true)]).to include( be_happy )
        expect([double("actual", :happy? => false)]).not_to include( be_happy )
      end
    end
  end
end