Class: RuboCop::Cop::RSpecRails::MinitestAssertions::BasicAssertion
- Inherits:
-
Object
- Object
- RuboCop::Cop::RSpecRails::MinitestAssertions::BasicAssertion
- Extended by:
- NodePattern::Macros
- Defined in:
- lib/rubocop/cop/rspec_rails/minitest_assertions.rb
Overview
:nodoc:
Direct Known Subclasses
EmptyAssertion, EqualAssertion, FalseAssertion, InDeltaAssertion, IncludesAssertion, InstanceOfAssertion, KindOfAssertion, MatchAssertion, NilAssertion, PredicateAssertion, TrueAssertion
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#failure_message ⇒ Object
readonly
Returns the value of attribute failure_message.
Class Method Summary collapse
Instance Method Summary collapse
- #assertion ⇒ Object
-
#initialize(expected, actual, failure_message) ⇒ BasicAssertion
constructor
A new instance of BasicAssertion.
- #negated?(node) ⇒ Boolean
- #replaced(node) ⇒ Object
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, ) @expected = expected&.source @actual = actual.source @failure_message = &.source end |
Instance Attribute Details
#actual ⇒ Object (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 |
#expected ⇒ Object (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_message ⇒ Object (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 end |
Class Method Details
.minitest_assertion ⇒ Object
41 42 43 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 41 def self.minitest_assertion raise NotImplementedError end |
Instance Method Details
#assertion ⇒ Object
64 65 66 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 64 def assertion raise NotImplementedError end |
#negated?(node) ⇒ 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 .nil? "expect(#{actual}).#{runner} #{assertion}" else "expect(#{actual}).#{runner}(#{assertion}, #{})" end end |