Sha256: 0226de0398fae99df5731a9c800775cc4a3592c636edd1d0fcd80998ea4ffe4e

Contents?: true

Size: 1.28 KB

Versions: 16

Compression:

Stored size: 1.28 KB

Contents

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

Version data entries

16 entries across 16 versions & 5 rubygems

Version Path
entitlements-app-1.2.0 lib/contracts-ruby3/spec/validators_spec.rb
contracts-0.17.2 spec/validators_spec.rb
contracts-0.17.1 spec/validators_spec.rb
entitlements-app-1.1.0 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-app-1.0.0 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-app-0.3.4 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-app-0.3.1 lib/contracts-ruby3/spec/validators_spec.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/contracts-0.17/spec/validators_spec.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/contracts-0.17/spec/validators_spec.rb
entitlements-app-0.3.0 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-0.2.1 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-app-0.2.1 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-0.2.0 lib/contracts-ruby3/spec/validators_spec.rb
entitlements-app-0.2.0 lib/contracts-ruby3/spec/validators_spec.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/contracts-0.17/spec/validators_spec.rb
contracts-0.17 spec/validators_spec.rb