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 80 81 82 83
|
# frozen_string_literal: true
RSpec.describe RuboCop::AST::ArgsNode do
let(:args_node) { parse_source(source).ast.arguments }
describe '.new' do
context 'with a method definition' do
let(:source) { 'def foo(x) end' }
it { expect(args_node.is_a?(described_class)).to be(true) }
end
context 'with a block' do
let(:source) { 'foo { |x| bar }' }
it { expect(args_node.is_a?(described_class)).to be(true) }
end
context 'with a lambda literal' do
let(:source) { '-> (x) { bar }' }
it { expect(args_node.is_a?(described_class)).to be(true) }
end
end
describe '#empty_and_without_delimiters?' do
subject { args_node.empty_and_without_delimiters? }
context 'with empty arguments' do
context 'with a method definition' do
let(:source) { 'def x; end' }
it { is_expected.to be(true) }
end
context 'with a block' do
let(:source) { 'x { }' }
it { is_expected.to be(true) }
end
context 'with a lambda literal' do
let(:source) { '-> { }' }
it { is_expected.to be(true) }
end
end
context 'with delimiters' do
context 'with a method definition' do
let(:source) { 'def x(); end' }
it { is_expected.to be(false) }
end
context 'with a block' do
let(:source) { 'x { || }' }
it { is_expected.to be(false) }
end
context 'with a lambda literal' do
let(:source) { '-> () { }' }
it { is_expected.to be(false) }
end
end
context 'with arguments' do
context 'with a method definition' do
let(:source) { 'def x a; end' }
it { is_expected.to be(false) }
end
context 'with a lambda literal' do
let(:source) { '-> a { }' }
it { is_expected.to be(false) }
end
end
end
end
|