Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Using my fork of clispec that supports a block syntax for #run() whic…

…h opens a fork to the command
  • Loading branch information...
commit 25206fd02487c83036b96c3cc293f714e2d746b0 1 parent 9d1695d
@bjeanes authored
View
5 bin/match 100644 → 100755
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
+lib = File.join(File.dirname(__FILE__),'..','lib')
+$: << lib unless $:.include? lib
require 'matrimony'
-
-Matrimony.run(*ARGV)
+Matrimony.run(ARGV)
View
5 bin/matrimony 100644 → 100755
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
+lib = File.join(File.dirname(__FILE__),'..','lib')
+$: << lib unless $:.include? lib
require 'matrimony'
-
-Matrimony.run(*ARGV)
+Matrimony.run(ARGV)
View
34 lib/matrimony.rb
@@ -1,7 +1,31 @@
-module Matrimony
- class << self
- def run(*args)
- puts "This is your first run!"
- end
+require 'rubygems'
+require 'highline'
+
+class Matrimony
+ def self.run(args)
+ new.run(*args)
+ end
+
+ def initialize
+ @io = HighLine.new($stdin, $stdout)
+ end
+
+ def run(*args)
+ say "This is your first run"
+ exit
+ end
+
+ private
+
+ def exit(status = 0)
+ Kernel.exit(status)
+ end
+
+ %w(agree ask choose color list say).each do |method|
+ class_eval %(
+ def #{method} *args
+ @io.#{method} *args
+ end
+ )
end
end
View
16 spec/matrimony_spec.rb
@@ -1,20 +1,20 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
-describe Matrimony do
+describe Matrimony, :type => :runner do
+ stub_exit!
+
describe "on first run" do
+ it_exits_successfully
+
it "should ask for development email address" do
- open('|-') do |command|
- if sub.nil?
- Matrimony.run # What the gem executable calls
- else
- command.gets.should =~ /This is your first run/
- end
+ run do |command|
+ command.gets.should =~ /This is your first run/
end
end
end
describe "after configuration" do
- matrimony_configured_with 'dev@mocra.com'
+ # matrimony_configured_with 'dev@mocra.com'
# ...
end
View
4 spec/spec_helper.rb
@@ -4,6 +4,10 @@
require 'spec'
require 'spec/autorun'
+gem 'clispec'
+require 'clispec'
+require 'clispec/example_groups/runner'
+
# Interesting reads
# http://devver.net/blog/2009/08/unit-testing-filesystem-interaction/
# http://devver.net/blog/2009/07/a-dozen-or-so-ways-to-start-sub-processes-in-ruby-part-2/
Please sign in to comment.
Something went wrong with that request. Please try again.