expertiza/expertiza

View on GitHub
spec/lib/scoring_spec.rb

Summary

Maintainability
C
1 day
Test Coverage

Block has too many lines. [289/25]
Open

describe Scoring do
  include Scoring
  let(:assignment_helper) { Class.new { extend AssignmentHelper } }
  let(:questionnaire) { create(:questionnaire, id: 1) }
  let(:question1) { create(:question, questionnaire: questionnaire, weight: 1, id: 1) }
Severity: Minor
Found in spec/lib/scoring_spec.rb by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

File scoring_spec.rb has 291 lines of code (exceeds 250 allowed). Consider refactoring.
Open

describe Scoring do
  include Scoring
  let(:assignment_helper) { Class.new { extend AssignmentHelper } }
  let(:questionnaire) { create(:questionnaire, id: 1) }
  let(:question1) { create(:question, questionnaire: questionnaire, weight: 1, id: 1) }
Severity: Minor
Found in spec/lib/scoring_spec.rb - About 3 hrs to fix

    Block has too many lines. [51/25]
    Open

      describe '#participant_scores' do
        before(:each) do
          allow(AssignmentQuestionnaire).to receive(:find_by).with(assignment_id: 1, questionnaire_id: 1)
                                                             .and_return(double('AssignmentQuestionnaire', used_in_round: 1))
          allow(questionnaire).to receive(:symbol).and_return(:review)
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [34/25]
    Open

      describe '#update_max_or_min' do
        context 'test updating the max' do
          it 'should not update the max if :max is nil' do
            scores = { round1: { scores: { max: nil } }, review: { scores: { max: 90 } } }
            # Scores[:review][:scores][:max] should not change to nil (currently 90)
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [34/25]
    Open

      describe '#compute_assignment_score' do
        before(:each) do
          allow(questionnaire).to receive(:symbol).and_return(:review)
          allow(assignment).to receive(:compute_total_score).with(any_args).and_return(100)
          allow(assignment).to receive(:questionnaires).and_return([questionnaire])
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [30/25]
    Open

      describe '#aggregate_assessment_scores' do
        let(:response1) { double('respons1') }
        let(:response2) { double('respons2') }
    
        before(:each) do
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        context 'test updating the max' do
          it 'should not update the max if :max is nil' do
            scores = { round1: { scores: { max: nil } }, review: { scores: { max: 90 } } }
            # Scores[:review][:scores][:max] should not change to nil (currently 90)
            ResponseMap.update_max_or_min(scores, :round1, :review, :max)
    Severity: Major
    Found in spec/lib/scoring_spec.rb and 1 other location - About 3 hrs to fix
    spec/lib/scoring_spec.rb on lines 236..253

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 109.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        context 'test updating the min' do
          it 'should not update the min if :min is nil' do
            scores = { round1: { scores: { min: nil } }, review: { scores: { min: 90 } } }
            # Scores[:review][:scores][:max] should not change to nil (currently 90)
            ResponseMap.update_max_or_min(scores, :round1, :review, :min)
    Severity: Major
    Found in spec/lib/scoring_spec.rb and 1 other location - About 3 hrs to fix
    spec/lib/scoring_spec.rb on lines 216..233

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 109.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Interpolation in single quoted string detected. Use double quoted strings if you need interpolation.
    Open

          it 'record the result as review#{n} scores' do
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks for interpolation in a single quoted string.

    Example:

    # bad
    
    foo = 'something with #{interpolation} inside'

    Example:

    # good
    
    foo = "something with #{interpolation} inside"

    Surrounding space missing for operator =>.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Surrounding space missing for operator =>.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Space inside { missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside { missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside { missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Surrounding space missing for operator =>.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Space inside } missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside } missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside } missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Ambiguous negative number operator. Parenthesize the method arguments if it's surely a negative number operator, or add a whitespace to the right of the - if it should be a subtraction.
    Open

          expect(assessment_score(response: [response], questions: [question1])).to eq -1.0
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.

    Example:

    # bad
    
    # The `*` is interpreted as a splat operator but it could possibly be
    # a `*` method invocation (i.e. `do_something.*(some_array)`).
    do_something *some_array

    Example:

    # good
    
    # With parentheses, there's no ambiguity.
    do_something(*some_array)

    Surrounding space missing for operator =>.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Surrounding space missing for operator =>.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Ambiguous negative number operator. Parenthesize the method arguments if it's surely a negative number operator, or add a whitespace to the right of the - if it should be a subtraction.
    Open

          expect(assessment_score(response: [response], questions: [question1])).to eq -1.0
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.

    Example:

    # bad
    
    # The `*` is interpreted as a splat operator but it could possibly be
    # a `*` method invocation (i.e. `do_something.*(some_array)`).
    do_something *some_array

    Example:

    # good
    
    # With parentheses, there's no ambiguity.
    do_something(*some_array)

    Space inside { missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside } missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside } missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Space inside { missing.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    (...) interpreted as grouped expression.
    Open

          expect(scores[:avg]).to eq (total_score1 + total_score2) / 2
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks for space between the name of a called method and a left parenthesis.

    Example:

    # bad
    
    puts (x + y)

    Example:

    # good
    
    puts(x + y)

    Surrounding space missing for operator =>.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Redundant curly braces around a hash parameter.
    Open

            expect(compute_reviews_hash(assignment)).to eq({1=>{1=>{1=>50}}, 2=>{1=>{1=>30}}})
    Severity: Minor
    Found in spec/lib/scoring_spec.rb by rubocop

    This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

    Example: EnforcedStyle: braces

    # The `braces` style enforces braces around all method
    # parameters that are hashes.
    
    # bad
    some_method(x, y, a: 1, b: 2)
    
    # good
    some_method(x, y, {a: 1, b: 2})

    Example: EnforcedStyle: no_braces (default)

    # The `no_braces` style checks that the last parameter doesn't
    # have braces around it.
    
    # bad
    some_method(x, y, {a: 1, b: 2})
    
    # good
    some_method(x, y, a: 1, b: 2)

    Example: EnforcedStyle: context_dependent

    # The `context_dependent` style checks that the last parameter
    # doesn't have braces around it, but requires braces if the
    # second to last parameter is also a hash literal.
    
    # bad
    some_method(x, y, {a: 1, b: 2})
    some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
    
    # good
    some_method(x, y, a: 1, b: 2)
    some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

    There are no issues that match your filters.

    Category
    Status