File: be_kind_of_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 (41 lines) | stat: -rw-r--r-- 1,352 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
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

module RSpec
  module Matchers
    [:be_a_kind_of, :be_kind_of].each do |method|
      describe "expect(actual).to #{method}(expected)" do
        it_behaves_like "an RSpec matcher", :valid_value => 5, :invalid_value => "a" do
          let(:matcher) { send(method, Fixnum) }
        end

        it "passes if actual is instance of expected class" do
          expect(5).to send(method, Fixnum)
        end

        it "passes if actual is instance of subclass of expected class" do
          expect(5).to send(method, Numeric)
        end

        it "fails with failure message for should unless actual is kind of expected class" do
          expect {
            expect("foo").to send(method, Array)
          }.to fail_with(%Q{expected "foo" to be a kind of Array})
        end

        it "provides a description" do
          matcher = be_a_kind_of(String)
          matcher.matches?("this")
          expect(matcher.description).to eq "be a kind of String"
        end
      end

      describe "expect(actual).not_to #{method}(expected)" do
        it "fails with failure message for should_not if actual is kind of expected class" do
          expect {
            expect("foo").not_to send(method, String)
          }.to fail_with(%Q{expected "foo" not to be a kind of String})
        end
      end
    end
  end
end