Skip to content

Commit

Permalink
Merge pull request #121 from davetron5000/remove-cucumber
Browse files Browse the repository at this point in the history
Remove cucumber
  • Loading branch information
davetron5000 authored Jul 9, 2018
2 parents 9bddce4 + bcc649e commit 859f5ad
Show file tree
Hide file tree
Showing 49 changed files with 838 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.1
2.5.1
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ notifications:
on_success: always
script: 'bundle exec rake'
rvm:
- 2.1.10
- 2.2.6
- 2.3.3
- 2.4.0
- jruby-19mode
- 2.4.3
- 2.5.1
120 changes: 74 additions & 46 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ Toward that end, this gem provides:
* A lightweight DSL to create your command-line interface, that loses none of <tt>OptionParser</tt>'s power.
* A simplified means of running external commands that has better error handling and diagnostics.
* Simplified zero-config logging that is a better-than-<tt>puts</tt> <tt>puts</tt>.
* Cucumber Steps, built on Aruba, to allow you to test-drive your command-line app development.
* Support for integration-testing your CLI using Test::Unit

== Tutorial

**This tutorial is somewhat outdated, but generally still applies**

http://a1.mzstatic.com/us/r30/Publication/v4/2c/f7/90/2cf7902f-f709-9125-c73d-87311216527d/MethadoneTutorial.225x225-75.jpg

{Tutorial for your iPad}[http://itunes.apple.com/us/book/kick-bash-habit-ruby-methadone/id515825242?ls=1] - This is a *free* iBooks interactive ebook that contains a step-by-step tutorial on making an awesome app with Methadone, including screencasts.
Expand All @@ -31,11 +33,13 @@ http://a1.mzstatic.com/us/r30/Publication/v4/2c/f7/90/2cf7902f-f709-9125-c73d-87

== Platforms

In general, we try to support {supported MRI Rubies}[https://www.ruby-lang.org/en/downloads/] as well as JRuby, however see the {Travis config file}[./.travis.yml] for specifics.
This library only supports the latest versions of Ruby. JRuby support has been too difficult to keep up with, though the library should work for JRuby.

See the {Travis config file}[./.travis.yml] for specifics.

== Bootstrapping a new CLI App

The +methadone+ command-line app will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and cucumber-based tests with aruba.
The +methadone+ command-line app will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and integration tests.

It assumes you are using a standard Ruby development environment, which includes:

Expand All @@ -47,41 +51,83 @@ _(Note that apps *powered* by this gem have no particular runtime dependencies a


$ methadone --help
Usage: methadone [options] app_name

Kick the bash habit by bootstrapping your Ruby command-line apps

v2.0.0

Options:
-h, --help Show command line help
--force Overwrite files if they exist
--[no-]readme [Do not ]produce a README file
--rspec Generate RSpec unit tests instead of Test::Unit
-l, --license LICENSE Specify the license for your project
(mit|apache|gplv2|gplv3|custom|NONE)
--log-level LEVEL Set the logging level
(debug|info|warn|error|fatal)
(Default: info)
--version Show help/version info

Arguments:

app_name
Name of your app, which is used for the gem name and executable name





Usage: methadone [options] app_name
--force Overwrite files if they exist
$ methadone newgem
$ cd newgem
$ bundle
$ rake
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
1 scenario (1 passed)
3 steps (3 passed)
$ cat features/newgem.feature
Feature: My bootstrapped app kinda works
In order to get going on coding my awesome app
I want to have aruba and cucumber setup
So I don't have to do it myself

Scenario: App just runs
When I run `newgem --help`
Then the exit status should be 0
And the output should contain:
"""
Usage: newgem [options]
"""
$ methadone myapp -l mit
$ cd myapp
$ bundle install
...
$ bundle exec rake
Started
.
Finished in 0.000499 seconds.
-----------------------------------------------------------------------------------------
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-----------------------------------------------------------------------------------------
2004.01 tests/s, 2004.01 assertions/s
Started
.
Finished in 0.298281 seconds.
-----------------------------------------------------------------------------------------
1 tests, 8 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-----------------------------------------------------------------------------------------
3.35 tests/s, 26.82 assertions/s

$ cat test/integration/test_cli.rb
require "methadone/test/base_integration_test"

class TestSomething < Methadone::BaseIntegrationTest
def test_truth
stdout,stderr,results = run_app("myapp","--help")
assert_banner(stdout, "myapp", takes_options: true, takes_arguments: false)
assert_option(stdout,"-h", "--help")
assert_option(stdout,"--version")
assert_oneline_summary(stdout)
end
end


Basically, this sets you up with all the boilerplate that you *should* be using to write a command-line app. Specifically, you get:

* Gemified project (based on <tt>bundle gem</tt>)
* An executable using Methadone::Main to outline your new app
* <tt>Test::Unit</tt> test task set up and an empty unit test.
* Aruba/Cucumber set up with a basic feature that exercise your executable
* <tt>Test::Unit</tt> integration tests with some of methadone's assertions to let you drive your CLI's development
* The outline of a README
* An optional license included

== DSL for your <tt>bin</tt> file

A canonical <tt>OptionParser</tt> driven app has a few problems with it structurally that Methadone can solve:
A canonical <tt>OptionParser</tt>-driven app has a few problems with it structurally that Methadone can solve:

* Backwards organization - main logic is at the bottom of the file, not the top
* Verbose to use +opts.on+ just to set a value in a +Hash+
Expand Down Expand Up @@ -129,32 +175,14 @@ Methadone::CLILogger is designed to handle this. It's a proper subclass of Ruby

See {CLILogger's rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogger.html] and then {CLILogging's}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogging.html] for more.


Currently, there are classes that assist in directing output logger-style to the right place; basically ensuring that errors go to +STDERR+ and everything else goes to +STDOUT+. All of this is, of course, configurable

== Cucumber Steps

Methadone uses aruba[http://www.github.com/cucumber/aruba] for BDD-style testing with cucumber. This library has some awesome steps, and Methadone provides additional, more opinionated, steps.

=== Example

Here's an example from methadone's own tests:

Scenario: Help is properly documented
When I get help for "methadone"
Then the exit status should be 0
And the following options should be documented:
|--force|
And the banner should be present
And the banner should include the version
And the banner should document that this app takes options
And the banner should document that this app's arguments are:
|app_name|which is required|
|dir_name|which is optional|
== Integration Tests

See Methadone::Cucumber or its {rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/Cucumber.html] for a list of all the steps provided.
Methadone provides some basic features for executing your CLI and asserting things about it. Methadone::Test::IntegrationTestAssertions documents these.

== Contributing

* Feel free to file an issue, even if you don't have time to submit a patch
* Please try to include a test for any patch you submit. If you don't include a test, I'll have to write one, and it'll take longer to get your code in.
* This is not intended to support “command-suite” style CLIs. See {GLI}[http://naildrivin5.com/gli] if that's what you want.
54 changes: 25 additions & 29 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,37 @@ require 'sdoc'
require 'bundler'
require 'rake/clean'
require 'rake/testtask'
require 'cucumber'
require 'cucumber/rake/task'

include Rake::DSL

Bundler::GemHelper.install_tasks

desc 'run tests'
desc 'run unit tests'
Rake::TestTask.new do |t|
t.libs << "lib"
t.libs << "test"
t.ruby_opts << "-rrubygems"
t.test_files = FileList['test/test_*.rb'] + FileList['test/execution_strategy/test_*.rb']
t.libs << "test/unit"
test_file = ENV["TEST"]
ENV.delete("TEST")
t.test_files = if test_file
[test_file]
else
FileList['test/unit/test_*.rb'] +
FileList['test/unit/execution_strategy/test_*.rb'] +
FileList['test/unit/test/test_*.rb']
end
end

desc 'run integration tests'
Rake::TestTask.new("test:integration") do |t|
t.libs << "lib"
t.libs << "test/integration"
test_file = ENV["TEST"]
ENV.delete("TEST")
t.test_files = if test_file
[test_file]
else
FileList['test/integration/test_*.rb']
end
end

desc 'build rdoc'
Expand Down Expand Up @@ -70,29 +88,7 @@ task :hack_css do
end
end
end
if RUBY_PLATFORM == 'java'
task :features do
puts "Aruba doesn't work on JRuby; cannot run features"
end
task 'features:wip' => :features
else
CUKE_RESULTS = 'results.html'
CLEAN << CUKE_RESULTS
Cucumber::Rake::Task.new(:features) do |t|
tag_opts = ' --tags ~@pending'
tag_opts = " --tags #{ENV['TAGS']}" if ENV['TAGS']
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
t.fork = false
end

Cucumber::Rake::Task.new('features:wip') do |t|
tag_opts = ' --tags ~@pending'
tag_opts = ' --tags @wip'
t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
t.fork = false
end
end

CLEAN << "coverage"
CLOBBER << FileList['**/*.rbc']
task :default => [:test, :features]
task :default => [:test, "test:integration"]
18 changes: 13 additions & 5 deletions bin/methadone
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ main do |app_name|
file =~ /\.rb$/ && file !~ /version.rb$/
}.first
end
rm_rf "#{gemname}/spec" # Don't want the default RSpec droppings
rm_rf "#{gemname}/.rspec"

require_file = gemname if require_file.nil?
require_file.gsub!(/^.*lib\//,'')

Expand All @@ -37,7 +40,7 @@ main do |app_name|

rspec = options[:rspec]

["Rakefile", ".gitignore", "features/support/env.rb"].each do |file|
["Rakefile", ".gitignore", ].each do |file|
copy_file file, :binding => binding
end

Expand All @@ -46,7 +49,8 @@ main do |app_name|
copy_file "spec/something_spec.rb", :from => :rspec, :binding => binding
else
template_dirs_in(:test_unit).each { |dir| mkdir_p dir }
copy_file "test/tc_something.rb", :from => :test_unit, :binding => binding
copy_file "test/unit/test_something.rb", :from => :test_unit, :binding => binding
copy_file "test/integration/test_cli.rb", :from => :test_unit, :binding => binding
end


Expand All @@ -71,18 +75,21 @@ main do |app_name|
else
gemspec_content.gsub!(/(^\s*#{gem_variable}\.name\s*=\s*.*)/,"\\1\n#{" #{gem_variable}.license".ljust(20)} = #{license.to_s.inspect.upcase}")
end
# RubyGems won't deal with a gemspec in this state and so Bundler won't even
# work at all. This is not helpful, so replace the magic keys its looking for
# with something else
gemspec_content.gsub!(/TODO/,"to-do")
gemspec_content.gsub!(/FIXME/,"fix me")
gemspec_content.gsub!(/^.*\.homepage.*$/,"")
File.open(gemspec,'w') {|f| f.write gemspec_content }


copy_file "README.rdoc", :binding => binding if using_readme

copy_file "features/executable.feature", :as => "#{gemname}.feature", :binding => binding
copy_file "features/step_definitions/executable_steps.rb", :as => "#{gemname}_steps.rb"
copy_file "bin/executable", :as => gemname, :executable => true, :binding => binding

add_to_file gemspec, [
" #{gem_variable}.add_development_dependency('rdoc')",
" #{gem_variable}.add_development_dependency('aruba')",
" #{gem_variable}.add_dependency('methadone', '~> #{Methadone::VERSION}')",
], :before => /^end\s*$/
ruby_major,ruby_minor,ruby_patch = RUBY_VERSION.split(/\./).map(&:to_i)
Expand All @@ -98,6 +105,7 @@ main do |app_name|
" #{gem_variable}.add_development_dependency('rspec', '~> 3')",
], :before => /^end\s*$/
end
FileUtils.rm_f "README.md", verbose: true

sh! %q(git add --all .)
end
Expand Down
Loading

0 comments on commit 859f5ad

Please sign in to comment.