| Conditions | 8 |
| Total Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned |
||
| 43 | |||
| 44 | def describe_update(): |
||
| 45 | |||
| 46 | @pytest.fixture |
||
| 47 | def slug(): |
||
| 48 | return SLUG + "/update" |
||
| 49 | |||
| 50 | def it_can_update_metrics(env, slug): |
||
| 51 | cmd = cli(env, slug, 'unit', '100') |
||
| 52 | |||
| 53 | expect(cmd.returncode) == 0 |
||
| 54 | expect(cmd.stderr) == "" |
||
| 55 | expect(cmd.stdout) == "" |
||
| 56 | |||
| 57 | def it_indicates_when_metrics_decrease(env, slug): |
||
| 58 | cmd = cli(env, slug, 'unit', '0') |
||
| 59 | |||
| 60 | expect(cmd.returncode) == 0 |
||
| 61 | expect(cmd.stderr) == "" |
||
| 62 | expect(cmd.stdout).contains("coverage decreased") |
||
| 63 | expect(cmd.stdout).contains( |
||
| 64 | "To reset metrics, run: coveragespace " + slug + " --reset" |
||
| 65 | ) |
||
| 66 | |||
| 67 | def it_fails_when_metrics_decrease_if_requested(env, slug): |
||
| 68 | cmd = cli(env, slug, 'unit', '0', '--exit-code') |
||
| 69 | |||
| 70 | expect(cmd.returncode) == 1 |
||
| 71 | expect(cmd.stderr) == "" |
||
| 72 | expect(cmd.stdout).contains("coverage decreased") |
||
| 73 | |||
| 74 | def it_always_display_metrics_when_verbose(env, slug): |
||
| 75 | cmd = cli(env, slug, 'unit', '100', '--verbose') |
||
| 76 | |||
| 77 | expect(cmd.returncode) == 0 |
||
| 78 | expect(cmd.stderr) != "" # expect lots of logging |
||
| 79 | expect(cmd.stdout).contains("coverage increased") |
||
| 80 | |||
| 81 | def it_skips_when_running_on_ci(env, slug): |
||
| 82 | env.environ['CI'] = 'true' |
||
| 83 | |||
| 84 | cmd = cli(env, slug, 'unit', '0', '--exit-code', '--verbose') |
||
| 85 | |||
| 86 | expect(cmd.returncode) == 0 |
||
| 87 | expect(cmd.stderr).contains("Coverage check skipped") |
||
| 88 | expect(cmd.stdout) == "" |
||
| 89 | |||
| 90 | def it_fails_on_slugs_missing_a_slash(env): |
||
| 91 | cmd = cli(env, 'foobar', 'unit', '100') |
||
| 92 | |||
| 93 | expect(cmd.returncode) == 1 |
||
| 94 | expect(cmd.stderr).contains( |
||
| 95 | "<owner/repo> slug must contain a slash") |
||
| 96 | expect(cmd.stdout) == "" |
||
| 110 |