黄瓜阿鲁巴试图改变一个奇怪的错误目录结果(Cucumber Aruba trying to chan

2019-10-18 11:05发布

所以我创建点文件目录,然后cd以点文件。 然而,黄瓜阿鲁巴是给我的,说点文件不是目录错误。 我想不通这是为什么? 该代码在正确的行为撬结果。

  @creation
  Scenario: Create a dotfiles git repository
    Given the directory dotfiles does not exist in the home directory
    When I successfully run `dotfiles init dotfile_one dotfile_two dotfile_three`
    Then a dotfiles directory should exist in the home directory
    When I change directory to the dotfiles directory ### Fails here ###
    Then a file named ".git" should exist

我的脚步

Given /^the directory dotfiles does not exist in the home directory$/ do
  step %(a directory named "#{ENV['HOME']}/dotfiles" should not exist)
end

Then /^a dotfiles directory should exist in the home directory$/ do
  step %(a directory named "#{ENV['HOME']}/dotfiles" should exist)
end

When /^I change directory to the dotfiles directory$/ do
  step %(I cd to "#{ENV['HOME']}/dotfiles")
end

前面的勾:

Before('@creation') do
  FileUtils.rm_rf(File.join(ENV['HOME'], 'dotfiles'))
end

来源

module Dotfiles
  class Repository

    def self.init(location, dotfiles)
      # create the dotfiles directory and git init
      FileUtils.chdir(location) do
        FileUtils.mkdir_p(File.join location, 'dotfiles')
      end
      FileUtils.chdir(File.join location, 'dotfiles')
    end

  end
end

短版的错误

When I change directory to the dotfiles directory                             # features/step_definitions/aruba_steps.rb:13
      tmp/aruba/Users/Brian/dotfiles is not a directory. (RuntimeError)

下面是完整的跟踪误差

@creation
  Scenario: Create a dotfiles git repository                                      # features/dotfiles_repository.feature:6
    Given the directory dotfiles does not exist in the home directory             # features/step_definitions/aruba_steps.rb:5
    When I successfully run `dotfiles init dotfile_one dotfile_two dotfile_three` # aruba-0.5.3/lib/aruba/cucumber.rb:71
    Then a dotfiles directory should exist in the home directory                  # features/step_definitions/aruba_steps.rb:9
    When I change directory to the dotfiles directory                             # features/step_definitions/aruba_steps.rb:13
      tmp/aruba/Users/Brian/dotfiles is not a directory. (RuntimeError)
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/aruba-0.5.3/lib/aruba/api.rb:22:in `cd'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/aruba-0.5.3/lib/aruba/cucumber.rb:52:in `block in <top (required)>'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/step_match.rb:25:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:60:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/rb_support/rb_world.rb:52:in `step'
      /Users/Brian/gems/dotfiles/features/step_definitions/aruba_steps.rb:14:in `block in <top (required)>'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/step_match.rb:25:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:60:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:38:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:106:in `block in visit_step'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:105:in `visit_step'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:19:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:18:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:18:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:100:in `block in visit_steps'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:99:in `visit_steps'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:15:in `block in execute'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:82:in `block (2 levels) in with_hooks'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:98:in `before_and_after'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:81:in `block in with_hooks'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:120:in `call'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:120:in `block (3 levels) in around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:9:in `block in around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:97:in `call'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:97:in `execute_around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:8:in `around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:119:in `block (2 levels) in around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:123:in `call'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:123:in `around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:93:in `around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:80:in `with_hooks'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:13:in `execute'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:32:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:31:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:58:in `block in visit_feature_element'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:57:in `visit_feature_element'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:38:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:37:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:37:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:28:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:17:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:17:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:27:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:48:in `run!'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/cli/main.rb:47:in `execute!'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/bin/cucumber:13:in `<top (required)>'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `load'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `<main>'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
      features/dotfiles_repository.feature:10:in `When I change directory to the dotfiles directory'
    Then a file named ".git" should exist                                         # aruba-0.5.3/lib/aruba/cucumber.rb:264

Failing Scenarios:
cucumber features/dotfiles_repository.feature:6 # Scenario: Create a dotfiles git repository

1 scenario (1 failed)
5 steps (1 failed, 1 skipped, 3 passed)
0m0.631s

任何人有任何解决方案或建议? 不要犹豫,问你是否有问题。 提前致谢

Answer 1:

我看到一对夫妇的事情,我会做出不同。 有没有保证,这将有所作为,但它可能。

dotfiles永远不会在你的代码中使用。 'dotfiles'是,那么你为什么需要它作为一个参数?

def self.init(location, dotfiles)

红宝石可以解释这些线两种方式:

FileUtils.mkdir_p(File.join location, 'dotfiles')
FileUtils.chdir(File.join location, 'dotfiles')

注意括号中的差异,以迫使这些行参数分配:

FileUtils.mkdir_p(File.join(location), 'dotfiles')
FileUtils.mkdir_p(File.join(location, 'dotfiles'))

FileUtils.chdir(File.join(location), 'dotfiles')
FileUtils.chdir(File.join(location, 'dotfiles'))

而不是像写代码:

def self.init(location, dotfiles)
  # create the dotfiles directory and git init
  FileUtils.chdir(location) do
    FileUtils.mkdir_p(File.join location, 'dotfiles')
  end
  FileUtils.chdir(File.join location, 'dotfiles')
end

我会写这样的而不是:

def self.init(location)

  # create the dotfiles directory and git init
  FileUtils.chdir(location) do
    FileUtils.mkdir('dotfiles')
  end

  FileUtils.chdir('dotfiles')

end

虽然红宝石允许我们在不使用括号包围参数的方法,那就是问及堆栈溢出代码将无法正常工作无尽的许多问题的根源。 括号中是很重要的解释,以明确地告诉它我们真正的意思。 当你不使用它们,它会按照其正常的操作顺序和使用precendence的规则,试图找出一条线的部分应首先处理,不带括号强制操作的顺序,就可以犯错误。

我们的选择,在这一点上,是通往未来,我们要使用它的结果,或使用括号要清楚何时会发生什么的移动操作。



Answer 2:

我只是跑了类似的问题。 经过调查的很长一段时间此行引起了我的注意:

tmp/aruba/Users/Brian/dotfiles is not a directory. (RuntimeError)

请参阅如何与“TMP / Aruba的开始? 不用说,我的问题也有过这种“TMP /阿鲁巴/”就可以了。 如果你看一下在GitHub的自述不够紧密,你会发现,阿鲁巴有一个“中完成其文件操作的工作目录”。

当我跟着指示那里我得到了它正常的工作!



文章来源: Cucumber Aruba trying to change directory results in a strange error