spec/helper.rb in ver-2009.12.14 vs spec/helper.rb in ver-2010.02
- old
+ new
@@ -1,94 +1,65 @@
require 'bacon'
-Bacon.summary_at_exit
+# Bacon.summary_at_exit
-require 'pathname'
-
-# annoying fixes
-class Pathname
- alias / join
-
- def cp(dest)
- FileUtils.copy_file(expand_path.to_s, dest.to_s, preserve = true)
- end
-
- def =~(regexp)
- to_s =~ regexp
- end
-end
-
+$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'lib/ver'
-VER.run fork: false do
- Tk::After.idle do
- describe 'startup' do
- text = VER.layout.views.first.text
+module VER
+ class Spec
+ def initialize(&block)
+ @contexts = []
+ instance_eval(&block)
+ end
- should 'start with welcome buffer' do
- text.filename.to_s.should.end_with '.config/ver/welcome'
+ def run
+ if context = @contexts.shift
+ Tk::After.idle do
+ context.run
+ run
+ end
+ else
+ Tk::After.idle{ bacon_summary }
end
+ end
- should 'be at start of buffer' do
- text.index(:insert).to_s.should == "1.0"
- end
+ def describe(*args, &block)
+ @contexts << Bacon::Context.new(args.join(' '), &block)
end
- end
- Tk::After.idle do
- describe VER::Methods::Move do
- text = VER.layout.views.first.text
+ def bacon_summary
+ Bacon.handle_summary
- moving = lambda{|from, to, *args|
- from, to = text.index(from), text.index(to)
- $DEBUG = true
- text.mark_set(:insert, from)
- text.send(*args)
- text.index(:insert).should == to
- $DEBUG = false
- }
-
- should 'go a char forward' do
- moving['1.0', '1.1', :forward_char]
- moving['1.1', '1.2', :forward_char]
+ if $!
+ Kernel.raise $!
+ elsif Bacon::Counter[:errors] + Bacon::Counter[:failed] > 0
+ Kernel.exit 1
+ else
+ Kernel.exit 0
end
+ ensure
+ $stdout.flush
+ Tk.exit
+ end
+ end
- should 'go multiple chars forward' do
- moving['1.0', '1.10', :forward_char, 10]
- end
- should 'go a char backward' do
- moving['1.2', '1.1', :backward_char]
- moving['1.1', '1.0', :backward_char]
- end
+ # Schedule all describe blocks in a 'after idle' block that is scheduled by tcl.
+ # The last 'after idle' will output the bacon summary and call [Tk.exit].
+ # Not sure how well this handles nested describe blocks, but it might just work?
+ #
+ # @example usgage
+ # VER.spec do
+ # describe 'number of open buffers' do
+ # it 'should open one buffer by default' do
+ # VER.buffers.size.should == 1
+ # end
+ # end
+ # end
+ def self.spec(&block)
+ specs = Spec.new(&block)
- should 'go multiple chars backward' do
- moving['1.11', '1.1', :backward_char, 10]
- end
-
- should 'go to the beginning of a lines' do
- moving['2.20', '2.0', :beginning_of_line]
- end
-
- should 'go to the end of a line' do
- moving['2.0', '2.0 lineend', :end_of_line]
- end
-
- should 'go to a line number' do
- moving['2.0', '10.0', :go_line, 10]
- end
-
- should 'go to the end of a file' do
- moving['2.0', 'end - 1 chars', :end_of_file]
- end
-
- should 'go a page down' do
- moving['2.0', '2.1', :page_down]
- end
-
- should 'go a page up' do
- moving['2.0', '1.51', :page_up]
- end
+ VER.run fork: false do
+ specs.run
end
-
- EM.stop
end
end