card/spec/card/director_spec.rb
File director_spec.rb
has 302 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
RSpec.describe "Card::Director" do
STAGE_MAP = { VI: :initialize,
VP: :prepare_to_validate,
VV: :validate,
SP: :prepare_to_store,
- Create a ticketCreate a ticket
Method define_test_event
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def define_test_event stage, subcard
test_event stage, on: :create do
yield name
subcard "112v" if subcard && name == "11"
end
- Read upRead up
- Create a ticketCreate a ticket
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The first argument to describe should be the class or module being tested. Open
Open
RSpec.describe "Card::Director" do
- Create a ticketCreate a ticket
- Exclude checks
Do not suppress exceptions. Open
Open
rescue Card::Error
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for rescue blocks with no body.
Example:
# bad
def some_method
do_something
rescue
# do nothing
end
Example:
# bad
begin
do_something
rescue
# do nothing
end
Example:
# good
def some_method
do_something
rescue
handle_exception
end
Example:
# good
begin
do_something
rescue
handle_exception
end