|
507 | 507 | RUBY
|
508 | 508 | end
|
509 | 509 | end
|
| 510 | + |
| 511 | + context 'with predicate assertions' do |
| 512 | + it 'registers an offense when using `assert_predicate` with ' \ |
| 513 | + 'an actual predicate' do |
| 514 | + expect_offense(<<~RUBY) |
| 515 | + assert_predicate(a, :valid?) |
| 516 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(a).to be_valid`. |
| 517 | + RUBY |
| 518 | + |
| 519 | + expect_correction(<<~RUBY) |
| 520 | + expect(a).to be_valid |
| 521 | + RUBY |
| 522 | + end |
| 523 | + |
| 524 | + it 'registers an offense when using `assert_predicate` with ' \ |
| 525 | + 'an actual predicate and no parentheses' do |
| 526 | + expect_offense(<<~RUBY) |
| 527 | + assert_predicate a, :valid? |
| 528 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(a).to be_valid`. |
| 529 | + RUBY |
| 530 | + |
| 531 | + expect_correction(<<~RUBY) |
| 532 | + expect(a).to be_valid |
| 533 | + RUBY |
| 534 | + end |
| 535 | + |
| 536 | + it 'registers an offense when using `assert_predicate` with ' \ |
| 537 | + 'an actual predicate and a failure message' do |
| 538 | + expect_offense(<<~RUBY) |
| 539 | + assert_predicate a, :valid?, "must be valid" |
| 540 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(a).to(be_valid, "must be valid")`. |
| 541 | + RUBY |
| 542 | + |
| 543 | + expect_correction(<<~RUBY) |
| 544 | + expect(a).to(be_valid, "must be valid") |
| 545 | + RUBY |
| 546 | + end |
| 547 | + |
| 548 | + it 'registers an offense when using `assert_predicate` with ' \ |
| 549 | + 'an actual predicate and multi-line arguments' do |
| 550 | + expect_offense(<<~RUBY) |
| 551 | + assert_predicate(a, |
| 552 | + ^^^^^^^^^^^^^^^^^^^ Use `expect(a).to(be_valid, "must be valid")`. |
| 553 | + :valid?, |
| 554 | + "must be valid") |
| 555 | + RUBY |
| 556 | + |
| 557 | + expect_correction(<<~RUBY) |
| 558 | + expect(a).to(be_valid, "must be valid") |
| 559 | + RUBY |
| 560 | + end |
| 561 | + |
| 562 | + it 'registers an offense when using `assert_not_predicate` with ' \ |
| 563 | + 'an actual predicate' do |
| 564 | + expect_offense(<<~RUBY) |
| 565 | + assert_not_predicate a, :valid? |
| 566 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(a).not_to be_valid`. |
| 567 | + RUBY |
| 568 | + |
| 569 | + expect_correction(<<~RUBY) |
| 570 | + expect(a).not_to be_valid |
| 571 | + RUBY |
| 572 | + end |
| 573 | + |
| 574 | + it 'registers an offense when using `refute_predicate` with ' \ |
| 575 | + 'an actual predicate' do |
| 576 | + expect_offense(<<~RUBY) |
| 577 | + refute_predicate a, :valid? |
| 578 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `expect(a).not_to be_valid`. |
| 579 | + RUBY |
| 580 | + |
| 581 | + expect_correction(<<~RUBY) |
| 582 | + expect(a).not_to be_valid |
| 583 | + RUBY |
| 584 | + end |
| 585 | + |
| 586 | + it 'does not register an offense when using `expect(a).to be_predicate`' do |
| 587 | + expect_no_offenses(<<~RUBY) |
| 588 | + expect(a).to be_predicate |
| 589 | + RUBY |
| 590 | + end |
| 591 | + |
| 592 | + it 'does not register an offense when using ' \ |
| 593 | + '`expect(a).not_to be_predicate`' do |
| 594 | + expect_no_offenses(<<~RUBY) |
| 595 | + expect(a).not_to be_predicate |
| 596 | + RUBY |
| 597 | + end |
| 598 | + |
| 599 | + it 'does not register an offense when using `assert_predicate` with ' \ |
| 600 | + 'not a predicate' do |
| 601 | + expect_no_offenses(<<~RUBY) |
| 602 | + assert_predicate foo, :do_something |
| 603 | + RUBY |
| 604 | + end |
| 605 | + |
| 606 | + it 'does not register an offense when using `assert_not_predicate` with ' \ |
| 607 | + 'not a predicate' do |
| 608 | + expect_no_offenses(<<~RUBY) |
| 609 | + assert_not_predicate foo, :do_something |
| 610 | + RUBY |
| 611 | + end |
| 612 | + |
| 613 | + it 'does not register an offense when using `refute_predicate` with ' \ |
| 614 | + 'not a predicate' do |
| 615 | + expect_no_offenses(<<~RUBY) |
| 616 | + refute_predicate foo, :do_something |
| 617 | + RUBY |
| 618 | + end |
| 619 | + |
| 620 | + it 'does not register an offense when the predicate is not a symbol' do |
| 621 | + expect_no_offenses(<<~RUBY) |
| 622 | + assert_predicate a, 1 |
| 623 | + RUBY |
| 624 | + end |
| 625 | + |
| 626 | + it 'does not register an offense when the predicate is missing' do |
| 627 | + expect_no_offenses(<<~RUBY) |
| 628 | + assert_predicate a, "whoops, we forgot about the actual predicate!" |
| 629 | + RUBY |
| 630 | + end |
| 631 | + |
| 632 | + it 'does not register an offense when the predicate is a variable' do |
| 633 | + expect_no_offenses(<<~RUBY) |
| 634 | + foo = :foo? |
| 635 | +
|
| 636 | + assert_predicate a, foo |
| 637 | + RUBY |
| 638 | + end |
| 639 | + end |
510 | 640 | end
|
0 commit comments