for循环中的语法错误(Ruby / RSpec)

时间:2014-06-04 06:47:32

标签: ruby rspec

如下所示运行RSPEC测试时出现此错误:

Using Accessor#strict_set for specs
SyntaxError: /home/sam/projects/logstash.king-foo.dev/ansible/roles/logstash/spec/syslog.rb:6: syntax error, unexpected kEND
end
  ^
             load at org/jruby/RubyKernel.java:1101
           (root) at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:1
             each at org/jruby/RubyArray.java:1613
  load_spec_files at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896
  load_spec_files at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896
              run at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22

我尝试弄乱语法,但没有成功。

files = Dir['../configs/filter*.conf']
@@configuration = String.new
files.sort.each.do |file|
  @@configuration << File.read(file)
end

describe "my first logstash rspec test", :if => RUBY_ENGINE == "jruby"  do
  extend LogStash::RSpec

  config(@@configuration)
  ... some code here ...
end

有人知道我做错了什么吗? 为什么我会在结束语句和@@配置变量中得到语法错误?

1 个答案:

答案 0 :(得分:1)

错误表示代码中出现意外end。只需用

替换第3行即可
files.sort.each do |file|

我建议您使用{}代替doend{} 非太空敏感* ,您收到错误的可能性低于doend

*组成单词ALERT(是的,我知道,恶魔牙医)。