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 42 43 44 45 46 47
|
require "spec_helper"
RSpec.describe "Contract validators" do
subject(:o) { GenericExample.new }
describe "Range" do
it "passes when value is in range" do
expect do
o.method_with_range_contract(5)
end.not_to raise_error
end
it "fails when value is not in range" do
expect do
o.method_with_range_contract(300)
end.to raise_error(ContractError, /Expected: 1\.\.10/)
end
it "fails when value is incorrect" do
expect do
o.method_with_range_contract("hello world")
end.to raise_error(ContractError, /Expected: 1\.\.10.*Actual: "hello world"/m)
end
end
describe "Regexp" do
it "should pass for a matching string" do
expect { o.should_contain_foo("containing foo") }.to_not raise_error
end
it "should fail for a non-matching string" do
expect { o.should_contain_foo("that's not F00") }.to raise_error(ContractError)
end
describe "within a hash" do
it "should pass for a matching string" do
expect { o.hash_containing_foo({ :host => "foo.example.org" }) }.to_not raise_error
end
end
describe "within an array" do
it "should pass for a matching string" do
expect { o.array_containing_foo(["foo"]) }.to_not raise_error
end
end
end
end
|