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

Add missing steps for "Force overwrite" scenario #106

Closed mbigras closed 7 years ago

mbigras commented 7 years ago

I'm going to add to this tomorrow.

I've been working on adding the missing step definitions while working on the "Force overwrite" scenario.

Would love some feedback on if these step definitions are right. Especially wondering if reusing @repo_dir is okay to reuse in other steps.

This references https://github.com/mbigras/fullstop commit d97efd2 if it's easier to look at 😄

fullstop.feature

  Scenario: Force overwrite
    Given a git repo with some dotfiles at "/tmp/dotfiles.git"
    And I have my dotfiles cloned and symlinked to "~/dotfiles"
    And there's a new file in the git repo
    When I run `fullstop --force file:///tmp/dotfiles.git`
    Then the dotfiles in "~/dotfiles" should be re-cloned
    And the files in "~/dotfiles" should be symlinked in my home directory

fullstop_steps.rb

Given(/^I have my dotfiles cloned and symlinked to "([^"]*)"$/) do |dotfiles_dir|
  # fake out home
  base_dir = File.dirname(dotfiles_dir)
  base_dir = ENV['HOME'] if base_dir == "~"
  dotfiles_dir = File.join(base_dir,File.basename(dotfiles_dir))
  # clone dotfiles
  sh "git clone #{@repo_dir} #{dotfiles_dir}"

  # symlink dotfiles
  Dir.chdir dotfiles_dir do
    FILES.each do |file|
      sh "ln -s #{file} #{ENV['HOME']}"
    end
  end

end

Given(/^there's a new file in the git repo$/) do
    dotfile = ".foorc"
    Dir.chdir @repo_dir do
      FileUtils.touch(dotfile)
      sh "git add #{dotfile}"
      sh "git commit -a -m 'Add #{dotfile}'"
  end
end

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

  upstream_dotfiles = Dir.entries(@repo_dir).select {|f| !File.directory? f}
  downstream_dotfiles = Dir.entries(dotfiles_dir).select {|f| !File.directory? f}

  # should I compare these two?
  p upstream_dotfiles
  p downstream_dotfiles
end
davetron5000 commented 7 years ago

Hard to tell if they are right without trying them. Do they work? If you break your app, do they properly report failures?

Re-using ivars in these is usually fine assuming you are taking care to set it properly and clear it properly. I try to avoid it if I can include all the bits of state in the steps, but that's often not possible. I would expect steps like "Given a repo at …" to set up some state in ivars that other steps could rely on.