Module: Brut::SpecSupport::GeneralSupport::ClassMethods

Defined in:
lib/brut/spec_support/general_support.rb

Instance Method Summary collapse

Instance Method Details

#implementation_is_covered_by_other_tests(description) ⇒ Object

Used when a class’ implmentation is covered by other tests. This is better than omitting the test or having a blank one, as it makes it explicit that some other test covers this class’ behavior.

Parameters:

  • description (String)

    An explanation of what other tests cover this class’ implementation.



48
49
50
51
52
# File 'lib/brut/spec_support/general_support.rb', line 48

def implementation_is_covered_by_other_tests(description)
  it "has no tests because the implementation is sufficiently covered by other tests: #{description}" do
    expect(true).to eq(true)
  end
end

#implementation_is_needed(check_again_at:) ⇒ Object

Used to indicate that a test does need to be written, but that its implementation can wait until a given date before causing ‘bin/ci` to fail the test suite.



11
12
13
14
15
16
17
18
19
20
# File 'lib/brut/spec_support/general_support.rb', line 11

def implementation_is_needed(check_again_at:)
  check_again_at = if check_again_at.kind_of?(Time)
                     check_again_at
                   else
                     check_again_at = Date.parse(check_again_at).to_time
                   end
  it "has no tests for now, but they are needed eventually" do
    expect(Time.now < check_again_at).to eq(true),"It's after #{check_again_at}. Implementation is needed"
  end
end

#implementation_is_trivial(check_again_at: nil) ⇒ Object

To pass brut test audit with a class whose implementation is trivial, call this inside the RSpec ‘describe` block. This is better than an empty test as it makes it more explicit that you believe the implementation is trivial enough to not require a test. You can also set an expiration for this thinking.

Parameters:

  • check_again_at (Time|String) (defaults to: nil)

    if given, this will cause the test to fail after the given date/time. If passed as a string, ‘Date.parse` is used to convert it to a `Time`.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/brut/spec_support/general_support.rb', line 27

def implementation_is_trivial(check_again_at: nil)
  check_again_at = if check_again_at.nil?
                     nil
                   elsif check_again_at.kind_of?(Time)
                     check_again_at
                   else
                     check_again_at = Date.parse(check_again_at).to_time
                   end
  it "has no tests because the implementation is trivial#{check_again_at.nil? ? '' : ' for now'}" do
    if check_again_at.nil?
      expect(true).to eq(true)
    else
      expect(Time.now < check_again_at).to eq(true),"It's after #{check_again_at}. Check that the implementation of the class under test is still trivial. If it is, update or remove check_again_at:"
    end
  end
end