davetron5000 / optparse-plus

Start your command line scripts off right in Ruby
http://davetron5000.github.com/optparse-plus
Apache License 2.0
521 stars 54 forks source link

Three bugs in the wiki Happy Path Section #105

Closed mbigras closed 7 years ago

mbigras commented 7 years ago

Hi Dave,

I running into three problems in the wiki "Happy Path section" in features/step_definitions/fullstop_steps.rb I put the output of error messages, the diffs between what is on the wiki and the mods I made, and my ruby version. I'd be happy to change the wiki if you can confirm.

touch bug

The main error message is fatal: pathspec '.vimrc' did not match any files. Here is my fix in my repo

rm -rf dotfiles.git
mkdir dotfiles.git
git init .
Initialized empty Git repository in /private/tmp/dotfiles.git/.git/
git add .vimrc .bashrc .exrc
fatal: pathspec '.vimrc' did not match any files
  Scenario: Happy Path
    Given a git repo with some dotfiles at "/tmp/dotfiles.git"
      Command failed with status (128): [git add .vimrc .bashrc .exrc...](RuntimeError)
      ./features/step_definitions/fullstop_steps.rb:16:in `block (2 levels) in <top (required)>'
      ./features/step_definitions/fullstop_steps.rb:13:in `chdir'
      ./features/step_definitions/fullstop_steps.rb:13:in `/^a git repo with some dotfiles at "([^"]*)"$/'
      features/fullstop.feature:17:in `Given a git repo with some dotfiles at "/tmp/dotfiles.git"'
    When I successfully run "fullstop file:///tmp/dotfiles.git"
    Then the dotfiles should be checked out in the directory "~/dotfiles"
    And the files in "~/dotfiles" should be symlinked in my home directory

Failing Scenarios:
cucumber features/fullstop.feature:16

2 scenarios (1 failed, 1 passed)
11 steps (1 failed, 3 skipped, 7 passed)
0m0.613s

dir bug

The main error message is undefined local variable or method 'dir' for #<Object:0x007fad7f2afda8> (NameError). Here is my fix in my repo

Given a git repo with some dotfiles at "/tmp/dotfiles.git"
    The  /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version
    When I successfully run "fullstop file:///tmp/dotfiles.git"
    Then the dotfiles should be checked out in the directory "~/dotfiles"
      undefined local variable or method `dir' for #<Object:0x007fad7f2afda8> (NameError)
      ./features/step_definitions/fullstop_steps.rb:23:in `/^the dotfiles should be checked out in the directory "([^"]*)"$/'
      features/fullstop.feature:19:in `Then the dotfiles should be checked out in the directory "~/dotfiles"'

fix diffs

These are the two fixes and how they are different from the wiki.

➜  fullstop master ✓ git diff head~1 head~2
diff --git a/features/step_definitions/fullstop_steps.rb b/features/step_definitions/fullstop_steps.rb
index 3eaf1ad..21c3e3f 100644
--- a/features/step_definitions/fullstop_steps.rb
+++ b/features/step_definitions/fullstop_steps.rb
@@ -11,7 +11,7 @@ Given /^a git repo with some dotfiles at "([^"]*)"$/ do |repo_dir|
     mkdir dir
   end
   Dir.chdir repo_dir do
-    FILES.each { |_| FileUtils.touch _ }
+    FILES.each { |_| touch _ }
     sh "git init ."
     sh "git add #{FILES.join(' ')}"
     sh "git commit -a -m 'initial commit'"

➜  fullstop master ✓ git diff head~1
diff --git a/features/step_definitions/fullstop_steps.rb b/features/step_definitions/fullstop_steps.rb
index 3eaf1ad..d12df17 100644
--- a/features/step_definitions/fullstop_steps.rb
+++ b/features/step_definitions/fullstop_steps.rb
@@ -20,7 +20,7 @@ end

 Then /^the dotfiles should be checked out in the directory "([^"]*)"$/ do |dotfiles_dir|
   # Expand ~ to ENV["HOME"]
-  base_dir = File.dirname(dir)
+  base_dir = File.dirname(dotfiles_dir)
   base_dir = ENV['HOME'] if base_dir == "~"
   dotfiles_dir = File.join(base_dir,File.basename(dotfiles_dir))

➜  fullstop master ✓ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]

Deprecation warning/error

I'm trying to add the Happy Path feature. I looks like it's working as shown below:

➜  fullstop master ✗ ls /tmp | grep dot
dotfiles.git
➜  fullstop master ✗ ls /tmp | grep fake
fakehome
➜  fullstop master ✗ ls /tmp/fakehome
➜  fullstop master ✗ HOME=/tmp/fakehome bundle exec bin/fullstop /tmp/dotfiles.git
stderr output of 'git clone /tmp/dotfiles.git': Cloning into 'dotfiles'...
done.
➜  fullstop master ✗ ls -a /tmp/fakehome/dotfiles
.       ..      .bashrc .exrc   .git    .vimrc

However, the test is failing, and I'm also getting a deprecation warning:

The  /^I successfully run "(.*)"$/ step definition is deprecated. Please use the `backticks` version
    When I successfully run "fullstop file:///tmp/dotfiles.git"
      expected "fullstop file:///tmp/dotfiles.git" to be successfully executed (RSpec::Expectations::ExpectationNotMetError)
      features/fullstop.feature:18:in `When I successfully run "fullstop file:///tmp/dotfiles.git"'

I looked through the aruba project and found the place where it's being cited as deprecated here But the backticks version was failing so I just changed the feature and made a new step. I'm not sure if it's the right way but it did pass the

Then the dotfiles should be checked out in the directory "~/dotfiles" step:

feature: When foobar I successfully run "fullstop file:///tmp/dotfiles.git"

step:

When(/^foobar I successfully run "([^"]*)"$/) do |cmd|
  sh cmd 
end

Would love to know if anyone can replicate my bugs, and if the fixes work :smile:

Max