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, ResponseAssertion, 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.
49 50 51 52 53 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 49 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.
41 42 43 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 41 def actual @actual end |
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
41 42 43 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 41 def expected @expected end |
#failure_message ⇒ Object (readonly)
Returns the value of attribute failure_message.
41 42 43 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 41 def @failure_message end |
Class Method Details
.minitest_assertion ⇒ Object
43 44 45 46 47 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 43 def self.minitest_assertion # :nocov: raise NotImplementedError # :nocov: end |
Instance Method Details
#assertion ⇒ Object
68 69 70 71 72 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 68 def assertion # :nocov: raise NotImplementedError # :nocov: end |
#negated?(node) ⇒ Boolean
64 65 66 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 64 def negated?(node) node.method_name.start_with?('assert_not_', 'refute_') end |
#replaced(node) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/rubocop/cop/rspec_rails/minitest_assertions.rb', line 55 def replaced(node) runner = negated?(node) ? 'not_to' : 'to' if .nil? "expect(#{actual}).#{runner} #{assertion}" else "expect(#{actual}).#{runner}(#{assertion}, #{})" end end |