backtrace_spec.rb
1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
describe Backtrace, type: 'model' do
subject { described_class.new }
its(:fingerprint) { should be_present }
describe "#similar" do
context "no similar backtrace" do
its(:similar) { should be_nil }
end
context "similar backtrace exist" do
let!(:similar_backtrace) {
b = Fabricate(:backtrace)
b.fingerprint = fingerprint
b.save!
b
}
let(:fingerprint) { "fingerprint" }
before { allow(subject).to receive(:fingerprint).and_return(fingerprint) }
its(:similar) { should == similar_backtrace }
end
end
describe "find_or_create" do
subject { described_class.find_or_create(attributes) }
let(:attributes) { double :attributes }
let(:backtrace) { double :backtrace }
before { allow(described_class).to receive(:new).and_return(backtrace) }
context "no similar backtrace" do
before { allow(backtrace).to receive(:similar).and_return(nil) }
it "create new backtrace" do
expect(described_class).to receive(:create).with(attributes)
described_class.find_or_create(attributes)
end
end
context "similar backtrace exist" do
let(:similar_backtrace) { double :similar_backtrace }
before { allow(backtrace).to receive(:similar).and_return(similar_backtrace) }
it { should == similar_backtrace }
end
end
end