Rails 3.2.14 app。回购里面的黄瓜自动测试"供应商"夹。
我需要解析*.feature
个文件。
托尔任务
require './config/environment'
require "gherkin/tag_expression"
require "cucumber/runtime"
require 'cucumber'
class DB < Thor
include Thor::Actions
#...
desc 'test', 'test'
def generate_reports
tag_expression = Gherkin::TagExpression.new(["@mytag"])
file_list = get_list_of_files("features/myproject/")
features_object = Cucumber::Runtime::FeaturesLoader.new(file_list, [], tag_expression)
puts features_object.features[0].feature_elements.inspect
end
end
运行任务时出错:
/home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/feature_file.rb:58:in `initialize': No such file or directory - widget.feature. Please create a widget.feature directory to get started. (Errno::ENOENT)
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/feature_file.rb:58:in `open'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/feature_file.rb:58:in `source'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/feature_file.rb:37:in `parse'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/runtime/features_loader.rb:28:in `block in load'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/runtime/features_loader.rb:26:in `each'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/runtime/features_loader.rb:26:in `load'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/cucumber-1.3.15/lib/cucumber/runtime/features_loader.rb:14:in `features'
from /home/user/work/interface/lib/tasks/db.thor:56:in `test'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/runner.rb:36:in `method_missing'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:29:in `run'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:126:in `run'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /home/user/.rvm/rubies/ruby-2.1.1/lib/ruby/gems/2.1.0/gems/thor-0.19.1/bin/thor:6:in `<top (required)>'
from /home/user/.rvm/rubies/ruby-2.1.1/bin/thor:23:in `load'
from /home/user/.rvm/rubies/ruby-2.1.1/bin/thor:23:in `<main>'
from /home/user/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
from /home/user/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
当我在IRB中执行该操作时,一切正常。 问题是什么?或者是否有更好的方法来解析功能文件?
答案 0 :(得分:0)
Cucumber告诉你,它无法找到你要求它解析的文件,我怀疑你的get_list_of_files
方法正在返回.feature
个文件的列表而没有路径?
比较这两个代码示例,其中存在功能features/a_feature.feature
f = Cucumber::FeatureFile.new("a_feature.feature")
f.parse([], [])
#=> Errno::ENOENT: No such file or directory - a_feature.feature. Please create a a_feature.feature directory to get started.
与...比较
f = Cucumber::FeatureFile.new("features/a_feature.feature")
f.parse([], [])
#=> Cucumber::Ast::Feature(...)
我认为如果您的get_list_of_files
返回正确的相对路径,或者每个要素文件的完整路径,它应该按预期工作。