Skip to content

Commit

Permalink
Add some more basic matcher specs
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 27, 2013
1 parent c01f6ad commit 9e1caeb
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions spec/matchers_spec.rb
Expand Up @@ -49,6 +49,27 @@
end
end

describe "be_kind_of" do
it "passes if actual is kind of expected class" do
expect("foo").to be_kind_of(String)
expect("foo").to_not be_kind_of(Numeric)
end

it "passes if actual is kind of superclass of expected class" do
expect([]).to be_kind_of(Object)
end

it "fails if expected is not a kind of expected" do
expect {
expect("foo").to be_kind_of(Integer)
}.to raise_error(Exception)

expect {
expect("foo").to_not be_kind_of(String)
}.to raise_error(Exception)
end
end

describe "eq" do
it "matches when actual == expected" do
expect(:foo).to eq(:foo)
Expand All @@ -69,23 +90,42 @@
end
end

describe "be_kind_of" do
it "passes if actual is kind of expected class" do
expect("foo").to be_kind_of(String)
expect("foo").to_not be_kind_of(Numeric)
describe "eql" do
it "matches when expected.eql?(actual)" do
expect(1).to eql(1)
end

it "passes if actual is kind of superclass of expected class" do
expect([]).to be_kind_of(Object)
it "does not match when !expected.eql?(actual)" do
expect(1).to_not eql(:foo)
end

it "fails if expected is not a kind of expected" do
it "fails if matcher does not match" do
expect {
expect("foo").to be_kind_of(Integer)
expect(1).to eql(:bar)
}.to raise_error(Exception)

expect {
expect("foo").to_not be_kind_of(String)
expect(2).to_not eql(2)
}.to raise_error(Exception)
end
end

describe "include" do
it "matches if actual includes expected" do
expect("foo").to include("f")
expect([:foo, :bar, :baz]).to include(:baz)
expect({ :yellow => 'lorry' }).to include(:yellow)
end

it "does not match if actual does not inlcude expected" do
expect("foo").to_not include("b")
expect([:foo, :bar, :baz]).to_not include(:kapow)
expect({ :yellow => 'lorry' }).to_not include(:red)
end

it "fails if matcher does not match" do
expect {
expect("bar").to include("z")
}.to raise_error(Exception)
end
end

0 comments on commit 9e1caeb

Please sign in to comment.