Module | Spec::Runner::Context::InstanceMethods |
In: |
lib/spec/runner/context.rb
|
# File lib/spec/runner/context.rb, line 7 7: def initialize(name, &context_block) 8: @name = name 9: 10: @context_eval_module = ContextEvalModule.new 11: @context_eval_module.extend ContextEval::ModuleMethods 12: @context_eval_module.include ContextEval::InstanceMethods 13: before_context_eval 14: @context_eval_module.class_eval(&context_block) 15: end
# File lib/spec/runner/context.rb, line 29 29: def context_setup(&block) 30: @context_eval_module.context_setup(&block) 31: end
# File lib/spec/runner/context.rb, line 33 33: def context_teardown(&block) 34: @context_eval_module.context_teardown(&block) 35: end
# File lib/spec/runner/context.rb, line 25 25: def include(mod) 26: @context_eval_module.include mod 27: end
# File lib/spec/runner/context.rb, line 20 20: def inherit(klass) 21: @context_eval_module.inherit klass 22: end
# File lib/spec/runner/context.rb, line 67 67: def matches? name, matcher=nil 68: matcher ||= SpecMatcher.new name, @name 69: specifications.each do |spec| 70: return true if spec.matches_matcher? matcher 71: end 72: return false 73: end
# File lib/spec/runner/context.rb, line 83 83: def methods 84: my_methods = super 85: my_methods |= @context_eval_module.methods 86: my_methods 87: end
# File lib/spec/runner/context.rb, line 63 63: def number_of_specs 64: specifications.length 65: end
# File lib/spec/runner/context.rb, line 49 49: def run(reporter, dry_run=false) 50: reporter.add_context(@name) 51: prepare_execution_context_class 52: errors = run_context_setup(reporter, dry_run) 53: 54: specifications.each do |specification| 55: specification_execution_context = execution_context(specification) 56: specification_execution_context.copy_instance_variables_from(@once_only_execution_context_instance, [:@spec]) unless context_setup_block.nil? 57: specification.run(reporter, setup_block, teardown_block, dry_run, specification_execution_context) 58: end unless errors.length > 0 59: 60: run_context_teardown(reporter, dry_run) 61: end
# File lib/spec/runner/context.rb, line 75 75: def run_single_spec name 76: return if @name == name 77: matcher = SpecMatcher.new name, @name 78: specifications.reject! do |spec| 79: !spec.matches_matcher? matcher 80: end 81: end
# File lib/spec/runner/context.rb, line 37 37: def setup(&block) 38: @context_eval_module.setup(&block) 39: end
# File lib/spec/runner/context.rb, line 45 45: def specify(spec_name, opts={}, &block) 46: @context_eval_module.specify(spec_name, opts, &block) 47: end
# File lib/spec/runner/context.rb, line 41 41: def teardown(&block) 42: @context_eval_module.teardown(&block) 43: end
# File lib/spec/runner/context.rb, line 131 131: def context_modules 132: @context_eval_module.send :context_modules 133: end
# File lib/spec/runner/context.rb, line 95 95: def context_setup_block 96: @context_eval_module.send :context_setup_block 97: end
# File lib/spec/runner/context.rb, line 99 99: def context_teardown_block 100: @context_eval_module.send :context_teardown_block 101: end
# File lib/spec/runner/context.rb, line 139 139: def execution_context specification 140: execution_context_class.new(specification) 141: end
# File lib/spec/runner/context.rb, line 135 135: def execution_context_class 136: @context_eval_module.send :execution_context_class 137: end
# File lib/spec/runner/context.rb, line 91 91: def method_missing(*args) 92: @context_eval_module.method_missing(*args) 93: end
# File lib/spec/runner/context.rb, line 115 115: def prepare_execution_context_class 116: weave_in_context_modules 117: execution_context_class 118: end
# File lib/spec/runner/context.rb, line 143 143: def run_context_setup(reporter, dry_run) 144: errors = [] 145: unless dry_run 146: begin 147: @once_only_execution_context_instance = execution_context(nil) 148: @once_only_execution_context_instance.instance_eval(&context_setup_block) 149: rescue => e 150: errors << e 151: location = "context_setup" 152: reporter.spec_finished(location, e, location) if reporter 153: end 154: end 155: errors 156: end
# File lib/spec/runner/context.rb, line 158 158: def run_context_teardown(reporter, dry_run) 159: unless dry_run 160: begin 161: @once_only_execution_context_instance ||= execution_context(nil) 162: @once_only_execution_context_instance.instance_eval(&context_teardown_block) 163: rescue => e 164: location = "context_teardown" 165: reporter.spec_finished(location, e, location) if reporter 166: end 167: end 168: end
# File lib/spec/runner/context.rb, line 107 107: def setup_block 108: @context_eval_module.send :setup_block 109: end
# File lib/spec/runner/context.rb, line 103 103: def specifications 104: @context_eval_module.send :specifications 105: end
# File lib/spec/runner/context.rb, line 111 111: def teardown_block 112: @context_eval_module.send :teardown_block 113: end