/
casgn_node_spec.rb
55 lines (37 loc) · 1.09 KB
/
casgn_node_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
# frozen_string_literal: true
RSpec.describe RuboCop::AST::CasgnNode do
let(:casgn_node) { parse_source(source).ast }
describe '.new' do
context 'with a `casgn` node' do
let(:source) { 'VAR = value' }
it { expect(casgn_node).to be_a(described_class) }
end
end
describe '#namespace' do
include AST::Sexp
subject { casgn_node.namespace }
context 'when there is no parent' do
let(:source) { 'VAR = value' }
it { is_expected.to eq(nil) }
end
context 'when the parent is a `cbase`' do
let(:source) { '::VAR = value' }
it { is_expected.to eq(s(:cbase)) }
end
context 'when the parent is a `const`' do
let(:source) { 'FOO::VAR = value' }
it { is_expected.to eq(s(:const, nil, :FOO)) }
end
end
describe '#name' do
subject { casgn_node.name }
let(:source) { 'VAR = value' }
it { is_expected.to eq(:VAR) }
end
describe '#expression' do
include AST::Sexp
subject { casgn_node.expression }
let(:source) { 'VAR = value' }
it { is_expected.to eq(s(:send, nil, :value)) }
end
end