Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40d5616

Browse files
committed
Implemented the not_to expectation.
1 parent dd72803 commit 40d5616

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

examples/demo_expectations.pck

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ create or replace package demo_expectations is
4141
-- %test(demo of success for to_be_like expectation)
4242
procedure demo_to_be_like_success;
4343

44+
-- %test(demo of failure for not_to expectations)
45+
procedure demo_not_to_failure;
46+
47+
-- %test(demo of success for not_to expectations)
48+
procedure demo_not_to_success;
49+
4450
end;
4551
/
4652

@@ -469,5 +475,32 @@ create or replace package body demo_expectations is
469475
ut.expect( l_clob ).to_( be_like('a%a_TE%\_', '\') ); --escape wildcards with '\'
470476
end;
471477

478+
procedure demo_not_to_failure is
479+
begin
480+
ut.expect( 'Hi, I am Stephen' ).not_to( be_like('%Stephen') );
481+
ut.expect( 'stephen' ).not_to( match('^Stephen$', 'i') ); --case insensitive
482+
ut.expect( sysdate ).not_to( be_not_null() );
483+
ut.expect( to_char(null) ).not_to( be_null() );
484+
ut.expect( false ).not_to( be_false );
485+
ut.expect( true ).not_to( be_true );
486+
ut.expect( 123 ).not_to( be_false );
487+
ut.expect( sysdate ).not_to( be_true );
488+
ut.expect( 1 ).not_to( equal( 1 ) );
489+
ut.expect( 1 ).not_to( equal( '1' ) );
490+
ut.expect( to_char(null) ).not_to( equal( to_char(null) ) );
491+
end;
492+
493+
procedure demo_not_to_success is
494+
begin
495+
ut.expect( sysdate ).not_to( be_null() );
496+
ut.expect( to_char(null) ).not_to( be_not_null() );
497+
ut.expect( true ).not_to( be_false );
498+
ut.expect( false ).not_to( be_true );
499+
ut.expect( cast(null as boolean) ).not_to( be_false );
500+
ut.expect( cast(null as boolean) ).not_to( be_true );
501+
ut.expect( 1 ).not_to( equal( 2 ) );
502+
ut.expect( to_char(null) ).not_to( equal( to_char(null), a_nulls_are_equal=> false ) );
503+
end;
504+
472505
end;
473506
/

source/assertions/ut_assertion.tpb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ create or replace type body ut_assertion as
7878
self.to_( equal(a_expected) );
7979
end;
8080

81-
member procedure to_(self in ut_assertion, a_expectation ut_expectation) is
81+
final member procedure to_(self in ut_assertion, a_expectation ut_expectation) is
8282
l_assert_result boolean;
8383
l_assert_name varchar2(4000);
8484
l_expectation ut_expectation := a_expectation;
@@ -94,6 +94,22 @@ create or replace type body ut_assertion as
9494
end if;
9595
end;
9696

97+
final member procedure not_to(self in ut_assertion, a_expectation ut_expectation) is
98+
l_assert_result boolean;
99+
l_assert_name varchar2(4000);
100+
l_expectation ut_expectation := a_expectation;
101+
begin
102+
ut_utils.debug_log('ut_assertion.not_to(self in ut_assertion, a_expectation ut_expectation)');
103+
104+
l_assert_result := not l_expectation.run_expectation( self.actual_data );
105+
l_assert_name := 'not to '||l_expectation.name;
106+
if l_expectation.expected is not null then
107+
add_assert_result( l_assert_result, l_assert_name, l_expectation.additional_info, l_expectation.expected.to_string(), l_expectation.expected.type);
108+
else
109+
add_assert_result( l_assert_result, l_assert_name, l_expectation.additional_info );
110+
end if;
111+
end;
112+
97113
final member procedure to_be_null(self in ut_assertion) is
98114
begin
99115
ut_utils.debug_log('ut_assertion.to_be_null');

source/assertions/ut_assertion.tps

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ create or replace type ut_assertion as object
1515
member procedure to_equal(self in ut_assertion, a_expected timestamp_ltz_unconstrained, a_nulls_are_equal boolean := null),
1616
member procedure to_equal(self in ut_assertion, a_expected timestamp_tz_unconstrained, a_nulls_are_equal boolean := null),
1717
member procedure to_equal(self in ut_assertion, a_expected varchar2, a_nulls_are_equal boolean := null),
18-
member procedure to_(self in ut_assertion, a_expectation ut_expectation),
18+
final member procedure to_(self in ut_assertion, a_expectation ut_expectation),
19+
final member procedure not_to(self in ut_assertion, a_expectation ut_expectation),
1920
final member procedure to_be_null(self in ut_assertion),
2021
final member procedure to_be_not_null(self in ut_assertion)
2122
)

0 commit comments

Comments
 (0)