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
|
# File 'lib/legion/cli/lex/runner.rb', line 30
def add_function(name, function, args = nil)
@arg_keys = []
if args.nil?
args = '**'
else
option_args = ''
required_args = ''
args.split(',').each do |arg|
key, value = arg.split('=')
@arg_keys.push key.to_s
if value.nil? || value.empty?
required_args.concat("#{key}:, ")
else
option_args.concat("#{key}: '#{value}', ")
end
end
args = required_args.concat(option_args, '**')
end
insert_into_file "lib/legion/extensions/#{lex}/runners/#{name}.rb", after: "extend Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined? 'Helpers::Lex'\n" do
"
def #{function}(#{args})
{ success: true }
end\n"
end
insert_into_file("spec/runners/#{name}_spec.rb", after: "it { should be_a Module }\n") do
result = " it { is_expected.to respond_to(:#{function}).with_any_keywords }\n"
if @arg_keys.count.positive?
result.concat " it { is_expected.to respond_to(:#{function}).with_keywords(:#{@arg_keys.join(', :')}) }\n"
end
result
end
insert_into_file("spec/runners/#{name}_spec.rb", before: " end\n") do
" it('#{function} returns a success') { expect(test_class.#{function}[:success]).to eq true }\n"
end
end
|