/
be_eql_spec.rb
79 lines (67 loc) · 2.13 KB
/
be_eql_spec.rb
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::BeEql do
it 'registers an offense for `eql` when argument is a boolean' do
expect_offense(<<-RUBY)
it { expect(foo).to eql(true) }
^^^ Prefer `be` over `eql`.
it { expect(foo).to eql(false) }
^^^ Prefer `be` over `eql`.
RUBY
expect_correction(<<-RUBY)
it { expect(foo).to be(true) }
it { expect(foo).to be(false) }
RUBY
end
it 'registers an offense for `eql` when argument is an integer' do
expect_offense(<<-RUBY)
it { expect(foo).to eql(0) }
^^^ Prefer `be` over `eql`.
it { expect(foo).to eql(123) }
^^^ Prefer `be` over `eql`.
RUBY
expect_correction(<<-RUBY)
it { expect(foo).to be(0) }
it { expect(foo).to be(123) }
RUBY
end
it 'registers an offense for `eql` when argument is a float' do
expect_offense(<<-RUBY)
it { expect(foo).to eql(1.0) }
^^^ Prefer `be` over `eql`.
it { expect(foo).to eql(1.23) }
^^^ Prefer `be` over `eql`.
RUBY
expect_correction(<<-RUBY)
it { expect(foo).to be(1.0) }
it { expect(foo).to be(1.23) }
RUBY
end
it 'registers an offense for `eql` when argument is a symbol' do
expect_offense(<<-RUBY)
it { expect(foo).to eql(:foo) }
^^^ Prefer `be` over `eql`.
RUBY
expect_correction(<<-RUBY)
it { expect(foo).to be(:foo) }
RUBY
end
it 'registers an offense for `eql` when argument is nil' do
expect_offense(<<-RUBY)
it { expect(foo).to eql(nil) }
^^^ Prefer `be` over `eql`.
RUBY
expect_correction(<<-RUBY)
it { expect(foo).to be(nil) }
RUBY
end
it 'does not register an offense for `eql` when argument is a string' do
expect_no_offenses(<<-RUBY)
it { expect(foo).to eql('foo') }
RUBY
end
it 'does not register an offense for `eql` when expectation is negated' do
expect_no_offenses(<<-RUBY)
it { expect(foo).to_not eql(1) }
RUBY
end
end