Class: RuboCop::Cop::RSpecRails::MinitestAssertions::BasicAssertion

Inherits:
Object
  • Object
show all
Extended by:
NodePattern::Macros
Defined in:
lib/rubocop/cop/rspec_rails/minitest_assertions.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected, actual, failure_message) ⇒ BasicAssertion

Returns a new instance of BasicAssertion.



45
46
47
48
49
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 45

def initialize(expected, actual, failure_message)
  @expected = expected&.source
  @actual = actual.source
  @failure_message = failure_message&.source
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



39
40
41
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 39

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



39
40
41
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 39

def expected
  @expected
end

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



39
40
41
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 39

def failure_message
  @failure_message
end

Class Method Details

.minitest_assertionObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 41

def self.minitest_assertion
  raise NotImplementedError
end

Instance Method Details

#assertionObject

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 64

def assertion
  raise NotImplementedError
end

#negated?(node) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 60

def negated?(node)
  node.method_name.start_with?('assert_not_', 'refute_')
end

#replaced(node) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 51

def replaced(node)
  runner = negated?(node) ? 'not_to' : 'to'
  if failure_message.nil?
    "expect(#{actual}).#{runner} #{assertion}"
  else
    "expect(#{actual}).#{runner}(#{assertion}, #{failure_message})"
  end
end