Skip to content

Commit e890d8d

Browse files
committed
Enable rubocop-rspec plugin
1 parent 3b0108f commit e890d8d

22 files changed

+195
-161
lines changed

.rubocop.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins:
22
- rubocop-performance
33
- rubocop-rake
4+
- rubocop-rspec
45

56
AllCops:
67
TargetRubyVersion: '3.2'
@@ -92,3 +93,20 @@ Naming/VariableNumber:
9293

9394
Gemspec/DevelopmentDependencies:
9495
Enabled: false
96+
97+
# This might make sense, but I don't think it's worth moving things around for.
98+
RSpec/SpecFilePathFormat:
99+
Enabled: false
100+
# Sometimes it makes sense to have lots of assertions.
101+
RSpec/MultipleExpectations:
102+
Enabled: false
103+
# Sometimes it makes sense to have long tests.
104+
RSpec/ExampleLength:
105+
Enabled: false
106+
# This seems okay.
107+
RSpec/MultipleDescribes:
108+
Enabled: false
109+
# This seems to give a bunch of false positives. Specifically it's flagging
110+
# things where we are creating an object and checking no exception happens.
111+
RSpec/NoExpectationExample:
112+
Enabled: false

minfraud.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
3333
spec.add_development_dependency 'rubocop', '~> 1.23'
3434
spec.add_development_dependency 'rubocop-performance'
3535
spec.add_development_dependency 'rubocop-rake'
36+
spec.add_development_dependency 'rubocop-rspec'
3637
spec.add_development_dependency 'webmock', '~> 3.14'
3738
spec.metadata = {
3839
'rubygems_mfa_required' => 'true'

spec/assessments_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
require 'spec_helper'
44

55
describe Minfraud::Assessments do
6-
let(:resolver) { double(Minfraud::Resolver) }
7-
subject { described_class.new({}, resolver) }
6+
subject(:assessment) { described_class.new({}, resolver) }
7+
8+
let(:resolver) { class_double(Minfraud::Resolver) }
89

910
before { allow(resolver).to receive(:assign) }
1011

1112
%w[account billing credit_card custom_inputs device email event order payment shipping shopping_cart].each do |attribute|
1213
it "responds_to #{attribute}" do
13-
expect(subject).to respond_to(attribute)
14+
expect(assessment).to respond_to(attribute)
1415
end
1516
end
1617

1718
describe '#initialize' do
1819
it { is_expected.to be_an_instance_of described_class }
1920

2021
it 'calls resolver for components assignment' do
21-
expect(resolver).to have_received(:assign).with(subject, {})
22+
expect(resolver).to have_received(:assign).with(assessment, {})
2223
end
2324
end
2425

@@ -63,7 +64,7 @@
6364
]
6465

6566
tests.each do |i|
66-
assessment = Minfraud::Assessments.new(
67+
assessment = described_class.new(
6768
email: i[:email],
6869
)
6970
body = assessment.send :request_body

spec/components/account_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010

1111
it 'raises an exception for an invalid user_id' do
1212
expect do
13-
Minfraud::Components::Account.new(
13+
described_class.new(
1414
user_id: 'x' * 256,
1515
)
1616
end.to raise_exception(Minfraud::InvalidInputError)
1717
end
1818

1919
it 'raises an exception for an invalid username_md5' do
2020
expect do
21-
Minfraud::Components::Account.new(
21+
described_class.new(
2222
username_md5: 'd3b07384d113edec49eaa6238ad5ff0Z',
2323
)
2424
end.to raise_exception(Minfraud::InvalidInputError)
2525
end
2626

2727
it 'does not raise an exception if fields are not populated' do
28-
Minfraud::Components::Account.new
28+
described_class.new
2929
end
3030

3131
it 'does not raise an exception for valid values' do
32-
Minfraud::Components::Account.new(
32+
described_class.new(
3333
user_id: 10,
3434
username_md5: 'd3b07384d113edec49eaa6238ad5ff00',
3535
)

spec/components/base_spec.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,31 @@
33
require 'spec_helper'
44

55
describe Minfraud::Components::Base do
6+
subject(:base_component) { described_class.new }
7+
68
describe '#to_json' do
79
it 'has to be an instance of Hash' do
8-
expect(subject.to_json).to be_an_instance_of Hash
10+
expect(base_component.to_json).to be_an_instance_of Hash
911
end
1012

1113
context 'with no instance variables' do
1214
it 'has to be empty' do
13-
expect(subject.to_json).to be_empty
15+
expect(base_component.to_json).to be_empty
1416
end
1517
end
1618

1719
context 'with instance variables' do
1820
let(:expected) { { 'dummy' => 'test@example' } }
19-
before(:each) { subject.instance_variable_set(:@dummy, 'test@example') }
21+
22+
before { base_component.instance_variable_set(:@dummy, 'test@example') }
2023

2124
it 'returns json representation of attributes' do
22-
expect(subject.to_json).to eq(expected)
25+
expect(base_component.to_json).to eq(expected)
2326
end
2427

2528
it 'returns json while ignoring nil values' do
26-
subject.instance_variable_set(:@null, nil)
27-
expect(subject.to_json).to eq(expected)
29+
base_component.instance_variable_set(:@null, nil)
30+
expect(base_component.to_json).to eq(expected)
2831
end
2932
end
3033
end

spec/components/billing_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@
1010

1111
it 'raises an exception for an invalid region' do
1212
expect do
13-
Minfraud::Components::Billing.new(
13+
described_class.new(
1414
region: 'HIHIHI',
1515
)
1616
end.to raise_exception(Minfraud::InvalidInputError)
1717
end
1818

1919
it 'raises an exception for an invalid country' do
2020
expect do
21-
Minfraud::Components::Billing.new(
21+
described_class.new(
2222
country: 'HIHIHI',
2323
)
2424
end.to raise_exception(Minfraud::InvalidInputError)
2525
end
2626

2727
it 'raises an exception for an invalid phone_country_code' do
2828
expect do
29-
Minfraud::Components::Billing.new(
29+
described_class.new(
3030
phone_country_code: 'HIHIHI',
3131
)
3232
end.to raise_exception(Minfraud::InvalidInputError)
3333
end
3434

3535
it 'does not raise an exception for valid values' do
36-
Minfraud::Components::Billing.new(
36+
described_class.new(
3737
region: 'BC',
3838
country: 'CA',
3939
phone_country_code: '1',

spec/components/credit_card_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,57 @@
1010

1111
it 'raises an exception for an invalid issuer_id_number' do
1212
expect do
13-
Minfraud::Components::CreditCard.new(
13+
described_class.new(
1414
issuer_id_number: '5',
1515
)
1616
end.to raise_exception(Minfraud::InvalidInputError)
1717
end
1818

1919
it 'raises an exception for an invalid last_digits' do
2020
expect do
21-
Minfraud::Components::CreditCard.new(
21+
described_class.new(
2222
last_digits: '6',
2323
)
2424
end.to raise_exception(Minfraud::InvalidInputError)
2525
end
2626

2727
it 'raises an exception for an invalid last_4_digits' do
2828
expect do
29-
Minfraud::Components::CreditCard.new(
29+
described_class.new(
3030
last_4_digits: '6',
3131
)
3232
end.to raise_exception(Minfraud::InvalidInputError)
3333
end
3434

3535
it 'raises an exception for an invalid token' do
3636
expect do
37-
Minfraud::Components::CreditCard.new(
37+
described_class.new(
3838
token: '☃️',
3939
)
4040
end.to raise_exception(Minfraud::InvalidInputError)
4141
end
4242

4343
it 'raises an exception for an invalid token (all digits)' do
4444
expect do
45-
Minfraud::Components::CreditCard.new(
45+
described_class.new(
4646
token: '123',
4747
)
4848
end.to raise_exception(Minfraud::InvalidInputError)
4949
end
5050

5151
it 'does not raise an exception for valid values (deprecated last_4_digits)' do
52-
@cc = Minfraud::Components::CreditCard.new(
52+
cc = described_class.new(
5353
issuer_id_number: '123456',
5454
last_4_digits: '1234',
5555
token: 'abcd',
5656
was_3d_secure_successful: true,
5757
)
58-
expect(@cc.last_digits).to be(@cc.last_4_digits)
59-
expect(@cc.last_digits).to be('1234')
58+
expect(cc.last_digits).to be(cc.last_4_digits)
59+
expect(cc.last_digits).to be('1234')
6060
end
6161

6262
it 'does not raise an exception for valid values (eight digit issuer_id_number)' do
63-
Minfraud::Components::CreditCard.new(
63+
described_class.new(
6464
issuer_id_number: '12345678',
6565
last_4_digits: '1234',
6666
token: 'abcd',
@@ -69,18 +69,18 @@
6969
end
7070

7171
it 'does not raise an exception for valid values (two digit last_digits)' do
72-
@cc = Minfraud::Components::CreditCard.new(
72+
cc = described_class.new(
7373
issuer_id_number: '12345678',
7474
last_digits: '34',
7575
token: 'abcd',
7676
was_3d_secure_successful: true,
7777
)
78-
expect(@cc.last_digits).to be(@cc.last_4_digits)
79-
expect(@cc.last_digits).to be('34')
78+
expect(cc.last_digits).to be(cc.last_4_digits)
79+
expect(cc.last_digits).to be('34')
8080
end
8181

8282
it 'does not raise an exception for valid values (token is all digits)' do
83-
Minfraud::Components::CreditCard.new(
83+
described_class.new(
8484
issuer_id_number: '123456',
8585
last_digits: '1234',
8686
token: '1' * 20,
@@ -89,7 +89,7 @@
8989
end
9090

9191
it 'does not raise an exception when country is given and issuer_id_number is not provided' do
92-
Minfraud::Components::CreditCard.new(
92+
described_class.new(
9393
country: 'CA',
9494
)
9595
end

spec/components/custom_inputs_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
require 'spec_helper'
44

55
describe Minfraud::Components::CustomInputs do
6+
subject(:custom_inputs) { described_class.new(params) }
7+
68
let(:params) { { some_key: 'some value' } }
7-
subject { described_class.new(params) }
89

910
describe '#initialize' do
1011
it 'sets the params as instance variables' do
11-
expect(subject.instance_variable_get(:@some_key)).to eql(params[:some_key])
12+
expect(custom_inputs.instance_variable_get(:@some_key)).to eql(params[:some_key])
1213
end
1314
end
1415

@@ -19,30 +20,30 @@
1920

2021
it 'raises an exception for an invalid number' do
2122
expect do
22-
Minfraud::Components::CustomInputs.new(
23+
described_class.new(
2324
number: 1e13,
2425
)
2526
end.to raise_exception(Minfraud::InvalidInputError)
2627
end
2728

2829
it 'raises an exception for an invalid number (negative)' do
2930
expect do
30-
Minfraud::Components::CustomInputs.new(
31+
described_class.new(
3132
number: -1e13,
3233
)
3334
end.to raise_exception(Minfraud::InvalidInputError)
3435
end
3536

3637
it 'raises an exception for an invalid string' do
3738
expect do
38-
Minfraud::Components::CustomInputs.new(
39+
described_class.new(
3940
string: 'f' * 257,
4041
)
4142
end.to raise_exception(Minfraud::InvalidInputError)
4243
end
4344

4445
it 'does not raise an exception for valid values' do
45-
Minfraud::Components::CustomInputs.new(
46+
described_class.new(
4647
number: 10,
4748
string: 'foo',
4849
)

spec/components/device_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,52 @@
1010

1111
it 'raises an exception for an invalid IP' do
1212
expect do
13-
Minfraud::Components::Device.new(
13+
described_class.new(
1414
ip_address: 'foo',
1515
)
1616
end.to raise_exception(Minfraud::InvalidInputError)
1717
end
1818

1919
it 'raises an exception for an invalid IP (a network)' do
2020
expect do
21-
Minfraud::Components::Device.new(
21+
described_class.new(
2222
ip_address: '1.2.3.4/24',
2323
)
2424
end.to raise_exception(Minfraud::InvalidInputError)
2525
end
2626

2727
it 'raises an exception for an invalid session age' do
2828
expect do
29-
Minfraud::Components::Device.new(
29+
described_class.new(
3030
session_age: -1,
3131
)
3232
end.to raise_exception(Minfraud::InvalidInputError)
3333
end
3434

3535
it 'raises an exception for an invalid session age (too big)' do
3636
expect do
37-
Minfraud::Components::Device.new(
37+
described_class.new(
3838
session_age: 1e13,
3939
)
4040
end.to raise_exception(Minfraud::InvalidInputError)
4141
end
4242

4343
it 'does not raise an exception for valid values' do
44-
Minfraud::Components::Device.new(
44+
described_class.new(
4545
ip_address: '1.2.3.4',
4646
session_age: 10,
4747
)
4848
end
4949

5050
it 'does not raise an exception for valid values (IPv6)' do
51-
Minfraud::Components::Device.new(
51+
described_class.new(
5252
ip_address: 'dead::ffff',
5353
session_age: 100,
5454
)
5555
end
5656

5757
it 'does not raise an exception if no IP is provided' do
58-
Minfraud::Components::Device.new(
58+
described_class.new(
5959
session_age: 100,
6060
)
6161
end

0 commit comments

Comments
 (0)