spekmachine 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/testtask'
7
7
  require 'rake/rdoctask'
8
8
 
9
9
  PKG_NAME = "spekmachine"
10
- PKG_VERSION = '0.1.1'
10
+ PKG_VERSION = '0.2.0'
11
11
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12
12
  PKG_FILES = FileList[ '[A-Z]*', 'lib/**/*.rb' ]
13
13
 
@@ -31,7 +31,7 @@ spec = Gem::Specification.new do |s|
31
31
  s.author = "Michiel de Mare"
32
32
  s.homepage = "http://persia.rubyforge.org"
33
33
  s.rubyforge_project = "persia"
34
- s.add_dependency 'rspec' , '= 0.6.3'
34
+ s.add_dependency 'rspec' , '= 0.7.5'
35
35
  end
36
36
 
37
37
  Rake::GemPackageTask.new(spec) do |pkg|
data/bin/spekm CHANGED
@@ -1,20 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require_gem 'rspec', '= 0.6.3'
4
- require File.expand_path(File.dirname(__FILE__) + "/../lib/spekmachine") # better stack traces this way
5
-
6
- $context_runner = ::Spec::Runner::OptionParser.create_context_runner(ARGV, false, STDERR, STDOUT)
7
-
8
- # If ARGV is a glob, it will actually each over each one of the matching files.
9
- ARGV.each do |file_or_dir|
10
- if File.directory?(file_or_dir)
11
- Dir["#{file_or_dir}/**/*.rb"].each do |file|
12
- require file
13
- end
14
- else
15
- require file_or_dir
16
- end
17
- end
18
-
19
- $context_runner.run(true)
20
-
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+ require 'spekmachine'
4
+ ::Spec::Runner::CommandLine.run(ARGV, STDERR, STDOUT, true, true)
data/lib/spekmachine.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'rubygems'
2
+ require_gem 'rspec', '= 0.7.5'
1
3
  require 'spekmachine/runner/context'
2
4
  require 'spekmachine/runner/context_eval'
3
5
  require 'spekmachine/runner/context_runner'
4
- require 'spekmachine/runner/kernel_ext'
6
+ require 'spekmachine/runner/extensions/kernel'
5
7
  require 'spekmachine/runner/path'
@@ -17,33 +17,10 @@ module Spec
17
17
  @context_id
18
18
  end
19
19
 
20
- def before_context_eval
21
- end
22
-
23
- def inherit(klass)
24
- @context_eval_module.inherit klass
25
- end
26
-
27
- def include(mod)
28
- @context_eval_module.include mod
29
- end
30
-
31
20
  def goto(name, &block)
32
21
  @context_eval_module.goto(name, &block)
33
22
  end
34
23
 
35
- def setup(&block)
36
- @context_eval_module.setup(&block)
37
- end
38
-
39
- def teardown(&block)
40
- @context_eval_module.teardown(&block)
41
- end
42
-
43
- def specify(spec_name, &block)
44
- @context_eval_module.specify(spec_name, &block)
45
- end
46
-
47
24
  def jump_to(name)
48
25
  goto_parts[name].call
49
26
  end
@@ -54,98 +31,21 @@ module Spec
54
31
 
55
32
  def run(reporter, dry_run=false)
56
33
  reporter.add_context(@name)
57
-
58
34
  prepare_execution_context_class
59
- specifications.each do |specification|
60
- execution_context = execution_context_class.new(specification)
61
- #@exec_context.instance_variables.each {|v|
62
- # val = @exec_context.instance_variable_get(v)
63
- # execution_context.instance_variable_set v, val
64
- #}
65
- specification.run(reporter, nil, nil, dry_run, execution_context)
66
- end
67
- end
68
-
69
- def number_of_specs
70
- specifications.length
71
- end
72
-
73
- def matches? name, matcher=nil
74
- matcher ||= SpecMatcher.new name, @name
75
- specifications.each do |spec|
76
- return true if spec.matches_matcher? matcher
77
- end
78
- return false
79
- end
80
-
81
- def run_single_spec name
82
- return if @name == name
83
- matcher = SpecMatcher.new name, @name
84
- specifications.reject! do |spec|
85
- !spec.matches_matcher? matcher
86
- end
87
- end
88
-
89
- def methods
90
- my_methods = super
91
- my_methods |= @context_eval_module.methods
92
- my_methods
93
- end
35
+ errors = run_context_setup(reporter, dry_run)
94
36
 
95
- protected
96
-
97
- def method_missing(*args)
98
- @context_eval_module.method_missing(*args)
99
- end
100
-
101
- def specifications
102
- @context_eval_module.send :specifications
103
- end
104
-
105
- def setup_block
106
- @context_eval_module.send :setup_block
107
- end
108
-
109
- def teardown_block
110
- @context_eval_module.send :teardown_block
111
- end
112
-
113
- def setup_parts
114
- @context_eval_module.send :setup_parts
115
- end
116
-
117
- def teardown_parts
118
- @context_eval_module.send :teardown_parts
119
- end
120
-
121
- def prepare_execution_context_class
122
- weave_in_context_modules
123
- execution_context_class
124
- end
125
-
126
- def weave_in_context_modules
127
- mods = context_modules
128
- context_eval_module = @context_eval_module
129
- execution_context_class.class_eval do
130
- include context_eval_module
131
- mods.each do |mod|
132
- include mod
133
- end
134
- end
135
- end
136
-
137
- def context_modules
138
- @context_eval_module.send :context_modules
139
- end
140
-
141
- def execution_context_class
142
- @context_eval_module.send :execution_context_class
37
+ specifications.each do |specification|
38
+ specification_execution_context = execution_context(specification)
39
+ specification_execution_context.copy_instance_variables_from(@once_only_execution_context_instance, [:@spec]) unless context_setup_block.nil?
40
+ # only modification: setup_block & teardown_block are nil
41
+ specification.run(reporter, nil, nil, dry_run, specification_execution_context)
42
+ end unless errors.length > 0
43
+
44
+ run_context_teardown(reporter, dry_run)
143
45
  end
144
46
 
145
- def context_superclass
146
- @context_eval_module.send :context_superclass
147
- end
148
47
  end
48
+
149
49
  include InstanceMethods
150
50
  end
151
51
  end
@@ -2,119 +2,13 @@ module Spec
2
2
  module Runner
3
3
  module ContextEval
4
4
  module ModuleMethods
5
- def inherit(klass)
6
- @context_superclass = klass
7
- derive_execution_context_class_from_context_superclass
8
- end
9
-
10
- def include(mod)
11
- context_modules << mod
12
- end
13
-
14
- def setup(&block)
15
- setup_parts << block
16
- end
17
-
18
- def teardown(&block)
19
- teardown_parts << block
20
- end
21
-
22
5
  def goto(name, &block)
23
6
  goto_parts[name] = block
24
7
  end
25
8
 
26
- def specify(spec_name, &block)
27
- specifications << Specification.new(spec_name, &block)
28
- end
29
-
30
- def methods
31
- my_methods = super
32
- my_methods |= context_superclass.methods
33
- my_methods
34
- end
35
-
36
9
  def goto_parts
37
10
  @goto_parts ||= {}
38
11
  end
39
-
40
- protected
41
-
42
- def method_missing(method_name, *args)
43
- if context_superclass.respond_to?(method_name)
44
- return execution_context_class.send(method_name, *args)
45
- end
46
- super
47
- end
48
-
49
- def specifications
50
- @specifications ||= []
51
- end
52
-
53
- def setup_parts
54
- @setup_parts ||= []
55
- end
56
-
57
- def teardown_parts
58
- @teardown_parts ||= []
59
- end
60
-
61
- def setup_block
62
- parts = setup_parts.dup
63
-
64
- setup_method = begin
65
- context_superclass.instance_method(:setup)
66
- rescue
67
- nil
68
- end
69
- parts.unshift setup_method if setup_method
70
- create_block_from_parts(parts)
71
- end
72
-
73
- def teardown_block
74
- parts = teardown_parts.dup
75
-
76
- teardown_method = begin
77
- context_superclass.instance_method(:teardown)
78
- rescue
79
- nil
80
- end
81
- parts.unshift teardown_method if teardown_method
82
- create_block_from_parts(parts)
83
- end
84
-
85
- def create_block_from_parts(parts)
86
- proc do
87
- parts.each do |part|
88
- if part.is_a?(UnboundMethod)
89
- puts part.inspect
90
- part.bind(self).call
91
- else
92
- instance_exec(&part)
93
- end
94
- end
95
- end
96
- end
97
-
98
- def execution_context_class
99
- @execution_context_class ||= derive_execution_context_class_from_context_superclass
100
- end
101
-
102
- def derive_execution_context_class_from_context_superclass
103
- @execution_context_class = Class.new(context_superclass)
104
- @execution_context_class.class_eval do
105
- include ::Spec::Runner::ExecutionContext::InstanceMethods
106
- end
107
- end
108
-
109
- def context_superclass
110
- @context_superclass ||= Object
111
- end
112
-
113
- def context_modules
114
- @context_modules ||= []
115
- end
116
- end
117
- module InstanceMethods
118
12
  end
119
13
  end
120
14
  end
@@ -3,26 +3,10 @@
3
3
  module Spec
4
4
  module Runner
5
5
  class ContextRunner
6
- attr_reader :standalone
7
-
8
- def initialize(reporter, standalone, dry_run, single_spec=nil)
9
- @contexts = []
10
- @reporter = reporter
11
- @standalone = standalone
12
- @dry_run = dry_run
13
- @single_spec = single_spec
14
- end
15
-
16
6
  def set_start(name, block)
17
7
  @start_name = name
18
8
  @setup = block
19
9
  end
20
-
21
- def add_context(context)
22
- return if !@single_spec.nil? unless context.matches?(@single_spec)
23
- context.run_single_spec @single_spec if context.matches?(@single_spec)
24
- @contexts << context
25
- end
26
10
 
27
11
  def create_path(ctxMap)
28
12
  g = CPP.new
@@ -39,24 +23,33 @@ module Spec
39
23
  @setup.call
40
24
  cm = {}
41
25
  @contexts.each {|c| cm[c.context_id] = c }
42
- @reporter.start(number_of_specs)
43
- path = create_path(cm)
44
- path.each do |ctx, dest|
45
- ctx.run(@reporter, @dry_run)
46
- ctx.jump_to dest
26
+ @options.reporter.start(number_of_specs)
27
+ begin
28
+ path = create_path(cm)
29
+ path.each do |ctx, dest|
30
+ ctx.run(@options.reporter, @options.dry_run)
31
+ ctx.jump_to dest
32
+ end
33
+ rescue Interrupt
34
+ ensure
35
+ @options.reporter.end
47
36
  end
48
- @reporter.end
49
- failure_count = @reporter.dump
37
+ failure_count = @options.reporter.dump
38
+
39
+ if(failure_count == 0 && !@options.heckle_runner.nil?)
40
+ heckle_runner = @options.heckle_runner
41
+ @options.heckle_runner = nil
42
+ context_runner = self.class.new(@options)
43
+ context_runner.instance_variable_set(:@contexts, @contexts)
44
+ heckle_runner.heckle_with(context_runner)
45
+ end
46
+
50
47
  if(exit_when_done)
51
48
  exit_code = (failure_count == 0) ? 0 : 1
52
49
  exit(exit_code)
53
50
  end
51
+ failure_count
54
52
  end
55
-
56
- def number_of_specs
57
- @contexts.inject(0) {|sum, context| sum + context.number_of_specs}
58
- end
59
-
60
53
  end
61
54
  end
62
55
  end
@@ -0,0 +1,14 @@
1
+ require 'spec/runner/extensions/object'
2
+
3
+ module Kernel
4
+ def setup(name, &block)
5
+ runner = context_runner
6
+ runner.set_start(name, block)
7
+ end
8
+
9
+ def context(name, desc, &block)
10
+ context = Spec::Runner::Context.new(name, desc, &block)
11
+ context_runner.add_context(context)
12
+ end
13
+ end
14
+
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: spekmachine
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-12-22 00:00:00 +01:00
6
+ version: 0.2.0
7
+ date: 2007-01-09 00:00:00 +01:00
8
8
  summary: Stateful specs
9
9
  require_paths:
10
10
  - lib
@@ -34,8 +34,8 @@ files:
34
34
  - lib/spekmachine/runner/context.rb
35
35
  - lib/spekmachine/runner/context_eval.rb
36
36
  - lib/spekmachine/runner/context_runner.rb
37
- - lib/spekmachine/runner/kernel_ext.rb
38
37
  - lib/spekmachine/runner/path.rb
38
+ - lib/spekmachine/runner/extensions/kernel.rb
39
39
  test_files: []
40
40
 
41
41
  rdoc_options: []
@@ -56,5 +56,5 @@ dependencies:
56
56
  requirements:
57
57
  - - "="
58
58
  - !ruby/object:Gem::Version
59
- version: 0.6.3
59
+ version: 0.7.5
60
60
  version:
@@ -1,19 +0,0 @@
1
- module Kernel
2
- def setup(name, &block)
3
- runner = context_runner
4
- runner.set_start(name, block)
5
- end
6
-
7
- def context(name, desc, &block)
8
- context = Spec::Runner::Context.new(name, desc, &block)
9
- runner = context_runner
10
- runner.add_context(context)
11
- runner.run(false) if runner.standalone
12
- end
13
-
14
- private
15
-
16
- def context_runner
17
- $context_runner ||= ::Spec::Runner::OptionParser.create_context_runner(ARGV.dup, true, STDERR, STDOUT)
18
- end
19
- end