|
| 1 | +require "spec_helper" |
| 2 | +require "cc/engine/fingerprint" |
| 3 | + |
| 4 | +module CC::Engine |
| 5 | + describe Fingerprint do |
| 6 | + describe "#compute" do |
| 7 | + it "returns a fingerprint for method/class offenses" do |
| 8 | + cop_name = "Metrics/ModuleLength" |
| 9 | + path = "foo/bar.rb" |
| 10 | + message = "foo" |
| 11 | + |
| 12 | + computed = Fingerprint.new(path, cop_name, message).compute |
| 13 | + |
| 14 | + expect(computed).to eq "53a5f182884e58dcb16d24fca37e10bc" |
| 15 | + end |
| 16 | + |
| 17 | + it "returns nil for non method/class offenses" do |
| 18 | + cop_name = "Style/Foo" |
| 19 | + path = "foo/bar.rb" |
| 20 | + message = "foo" |
| 21 | + |
| 22 | + computed = Fingerprint.new(path, cop_name, message).compute |
| 23 | + |
| 24 | + expect(computed).not_to be |
| 25 | + end |
| 26 | + |
| 27 | + it "computes same fingerprint regardles of message url detail" do |
| 28 | + cop_name = "Metrics/ModuleLength" |
| 29 | + path = "foo/bar.rb" |
| 30 | + |
| 31 | + plain = "Metrics/MethodLength: Method has too many lines. [18/10]" |
| 32 | + verbose = "Metrics/MethodLength: Method has too many lines. [18/10] (https://github.com/bbatsov/ruby-style-guide#short-methods)" |
| 33 | + |
| 34 | + verbose_print = Fingerprint.new(path, cop_name, verbose).compute |
| 35 | + plain_print = Fingerprint.new(path, cop_name, plain).compute |
| 36 | + |
| 37 | + expect(verbose_print).to eq plain_print |
| 38 | + end |
| 39 | + |
| 40 | + it "computes same fingerprint regardles of line number detail" do |
| 41 | + old_count = "Metrics/MethodLength: Method has too many lines. [20/10]" |
| 42 | + improved_count = "Metrics/MethodLength: Method has too many lines. [18/10]" |
| 43 | + |
| 44 | + cop_name = "Metrics/ModuleLength" |
| 45 | + path = "foo/bar.rb" |
| 46 | + |
| 47 | + old_fingerprint = Fingerprint.new(path, cop_name, old_count).compute |
| 48 | + improved_fingerprint = Fingerprint.new(path, cop_name, improved_count).compute |
| 49 | + |
| 50 | + expect(old_fingerprint).to eq improved_fingerprint |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | +end |
0 commit comments