Skip to content

Commit

Permalink
docs: update examples details
Browse files Browse the repository at this point in the history
  • Loading branch information
ocvit committed Mar 11, 2024
1 parent b45ee3f commit 9536cc4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 78 deletions.
100 changes: 54 additions & 46 deletions examples/expectations_not_matched.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,67 +33,75 @@ class SumContract < Contr::Act
contract.check(*args) { args.inject(:+) }
# => Contr::Matcher::ExpectationsNotMatched: failed rules: [[:expectation, :arg_1_is_float, :failed], [:expectation, :arg_2_is_integer, :failed]], args: [1, 2.0]

# [if previous dump doesn't exist]
#
# state dumped to: /tmp/contracts/SumContract/2850248.dump
# [======= if previous dump doesn't exist =======]
#
# state:
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [
# {type: :expectation, name: :arg_1_is_float, status: :failed},
# {type: :expectation, name: :arg_2_is_integer, status: :failed}
# ],
# ok_rules: [
# {type: :guarantee, name: :result_is_float, status: :ok},
# {type: :guarantee, name: :result_is_positive, status: :ok},
# {type: :guarantee, name: :args_are_numbers, status: :ok}
# ],
# async: false,
# args: [1, 2.0],
# result: 3.0
# }
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [
# {type: :expectation, name: :arg_1_is_float, status: :failed},
# {type: :expectation, name: :arg_2_is_integer, status: :failed}
# ],
# ok_rules: [
# {type: :guarantee, name: :result_is_float, status: :ok},
# {type: :guarantee, name: :result_is_positive, status: :ok},
# {type: :guarantee, name: :args_are_numbers, status: :ok}
# ],
# async: false,
# args: [1, 2.0],
# result: 3.0
# }
#
# dumped to:
# /tmp/contracts/SumContract/2850248.dump
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":false,"args":[1,2.0],"result":3.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}

# [if previous dump exists]
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":false,"args":[1,2.0],"result":3.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}
#
#
# [======= if previous dump exists =======]
#
# state is not dumped once again (10 minutes window by default), but still logged - without `dump_info` field this time
# state is not dumped once again, but still logged - without `dump_info` field
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":false,"args":[1,2.0],"result":3.0,"tag":"contract-failed"}
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":false,"args":[1,2.0],"result":3.0,"tag":"contract-failed"}

contract.check_async(*args) { args.inject(:+) }
# => 3.0

# [if previous dump doesn't exist]
#
# state dumped to: /tmp/contracts/SumContract/2850248.dump
# [======= if previous dump doesn't exist =======]
#
# state:
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [
# {type: :expectation, name: :arg_1_is_float, status: :failed},
# {type: :expectation, name: :arg_2_is_integer, status: :failed}
# ],
# ok_rules: [
# {type: :guarantee, name: :result_is_float, status: :ok},
# {type: :guarantee, name: :result_is_positive, status: :ok},
# {type: :guarantee, name: :args_are_numbers, status: :ok}
# ],
# async: true,
# args: [1, 2.0],
# result: 3.0
# }
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [
# {type: :expectation, name: :arg_1_is_float, status: :failed},
# {type: :expectation, name: :arg_2_is_integer, status: :failed}
# ],
# ok_rules: [
# {type: :guarantee, name: :result_is_float, status: :ok},
# {type: :guarantee, name: :result_is_positive, status: :ok},
# {type: :guarantee, name: :args_are_numbers, status: :ok}
# ],
# async: true,
# args: [1, 2.0],
# result: 3.0
# }
#
# dumped to:
# /tmp/contracts/SumContract/2850248.dump
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":true,"args":[1,2.0],"result":3.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}

# [if previous dump exists]
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":true,"args":[1,2.0],"result":3.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}
#
#
# [======= if previous dump exists =======]
#
# state is not dumped once again (10 minutes window by default), but still logged - without `dump_info` field this time
# state is not dumped once again, but still logged - without `dump_info` field
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":true,"args":[1,2.0],"result":3.0,"tag":"contract-failed"}
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"expectation","name":"arg_1_is_float","status":"failed"},{"type":"expectation","name":"arg_2_is_integer","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"},{"type":"guarantee","name":"result_is_positive","status":"ok"},{"type":"guarantee","name":"args_are_numbers","status":"ok"}],"async":true,"args":[1,2.0],"result":3.0,"tag":"contract-failed"}
72 changes: 40 additions & 32 deletions examples/guarantees_not_matched.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,61 @@ class SumContract < Contr::Act
contract.check(*args) { args.inject(:+) }
# => Contr::Matcher::GuaranteesNotMatched: failed rules: [[:guarantee, :result_is_positive, :failed]], args: [1, -2.0]

# [if previous dump doesn't exist]
#
# state dumped to: /tmp/contracts/SumContract/2850248.dump
# [======= if previous dump doesn't exist =======]
#
# state:
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [{type: :guarantee, name: :result_is_positive, status: :failed}],
# ok_rules: [{type: :guarantee, name: :result_is_float, status: :ok}],
# async: false,
# args: [1, -2.0],
# result: -1.0
# }
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [{type: :guarantee, name: :result_is_positive, status: :failed}],
# ok_rules: [{type: :guarantee, name: :result_is_float, status: :ok}],
# async: false,
# args: [1, -2.0],
# result: -1.0
# }
#
# dumped to:
# /tmp/contracts/SumContract/2850248.dump
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":false,"args":[1,-2.0],"result":-1.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}

# [if previous dump exists]
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":false,"args":[1,-2.0],"result":-1.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}
#
#
# [======= if previous dump exists =======
#
# state is not dumped once again (10 minutes window by default), but still logged - without `dump_info` field this time
# state is not dumped once again, but still logged - without `dump_info` field
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":false,"args":[1,-2.0],"result":-1.0,"tag":"contract-failed"}
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":false,"args":[1,-2.0],"result":-1.0,"tag":"contract-failed"}

contract.check_async(*args) { args.inject(:+) }
# => -1.0

# [if previous dump doesn't exist]
#
# state dumped to: /tmp/contracts/SumContract/2850248.dump
# [======= if previous dump doesn't exist =======]
#
# state:
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [{type: :guarantee, name: :result_is_positive, status: :failed}],
# ok_rules: [{type: :guarantee, name: :result_is_float, status: :ok}],
# async: true,
# args: [1, -2.0],
# result: -1.0
# }
# {
# ts: "2024-03-11T09:23:04.245Z",
# contract_name: "SumContract",
# failed_rules: [{type: :guarantee, name: :result_is_positive, status: :failed}],
# ok_rules: [{type: :guarantee, name: :result_is_float, status: :ok}],
# async: true,
# args: [1, -2.0],
# result: -1.0
# }
#
# dumped to:
# /tmp/contracts/SumContract/2850248.dump
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":true,"args":[1,-2.0],"result":-1.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}

# [if previous dump exists]
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":true,"args":[1,-2.0],"result":-1.0,"dump_info":{"path":"/tmp/contracts/SumContract/2850248.dump"},"tag":"contract-failed"}
#
#
# [======= if previous dump exists =======
#
# state is not dumped once again (10 minutes window by default), but still logged - without `dump_info` field this time
# state is not dumped once again, but still logged - without `dump_info` field
#
# log:
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":true,"args":[1,-2.0],"result":-1.0,"tag":"contract-failed"}
# D, [2024-03-11T11:23:04.245811 #71262] DEBUG -- : {"ts":"2024-03-11T09:23:04.245Z","contract_name":"SumContract","failed_rules":[{"type":"guarantee","name":"result_is_positive","status":"failed"}],"ok_rules":[{"type":"guarantee","name":"result_is_float","status":"ok"}],"async":true,"args":[1,-2.0],"result":-1.0,"tag":"contract-failed"}

0 comments on commit 9536cc4

Please sign in to comment.