# File lib/spec/example/example_group_methods.rb, line 8 8: def build_description_from(*args) 9: text = args.inject("") do |description, arg| 10: description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/) 11: description << arg.to_s 12: end 13: text == "" ? nil : text 14: end
Makes the describe/it syntax available from a class. For example:
class StackSpec < Spec::ExampleGroup describe Stack, "with no elements" before @stack = Stack.new end it "should raise on pop" do lambda{ @stack.pop }.should raise_error end end
# File lib/spec/example/example_group_methods.rb, line 47 47: def describe(*args, &example_group_block) 48: raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty? 49: if example_group_block 50: options = add_options(args) 51: set_location(options, caller(0)[1]) 52: if options[:shared] 53: ExampleGroupFactory.create_shared_example_group(*args, &example_group_block) 54: else 55: subclass(*args, &example_group_block) 56: end 57: else 58: set_description(*args) 59: end 60: end
# File lib/spec/example/example_group_methods.rb, line 126 126: def described_class 127: @described_class ||= Class === described_type ? described_type : nil 128: end
# File lib/spec/example/example_group_methods.rb, line 122 122: def described_type 123: @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)} 124: end
# File lib/spec/example/example_group_methods.rb, line 118 118: def description 119: @description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s 120: end
# File lib/spec/example/example_group_methods.rb, line 130 130: def description_args 131: @description_args ||= [] 132: end
Creates an instance of the current example group class and adds it to a collection of examples of the current example group.
# File lib/spec/example/example_group_methods.rb, line 72 72: def example(description=nil, options={}, backtrace=nil, &implementation) 73: example_proxy = ExampleProxy.new(description, options, backtrace || caller(0)[1]) 74: example_proxies << example_proxy 75: example_implementations[example_proxy] = implementation || pending_implementation 76: example_proxy 77: end
# File lib/spec/example/example_group_methods.rb, line 156 156: def example_group_hierarchy 157: @example_group_hierarchy ||= ExampleGroupHierarchy.new(self) 158: end
# File lib/spec/example/example_group_methods.rb, line 164 164: def include_constants_in(mod) 165: include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod) 166: end
Use this to pull in examples from shared example groups.
# File lib/spec/example/example_group_methods.rb, line 64 64: def it_should_behave_like(*shared_example_groups) 65: shared_example_groups.each do |group| 66: include_shared_example_group(group) 67: end 68: end
# File lib/spec/example/example_group_methods.rb, line 168 168: def let(name, &block) 169: define_method name do 170: @assignments ||= {} 171: @assignments[name] ||= instance_eval(&block) 172: end 173: end
# File lib/spec/example/example_group_methods.rb, line 160 160: def nested_descriptions 161: example_group_hierarchy.nested_descriptions 162: end
# File lib/spec/example/example_group_methods.rb, line 79 79: def pending_implementation 80: lambda { raise(Spec::Example::NotYetImplementedError) } 81: end
# File lib/spec/example/example_group_methods.rb, line 94 94: def run(run_options) 95: examples = examples_to_run(run_options) 96: notify(run_options.reporter) unless examples.empty? 97: return true if examples.empty? 98: return dry_run(examples, run_options) if run_options.dry_run? 99: 100: define_methods_from_predicate_matchers 101: 102: success, before_all_instance_variables = run_before_all(run_options) 103: success, after_all_instance_variables = run_examples(success, before_all_instance_variables, examples, run_options) 104: success = run_after_all(success, after_all_instance_variables, run_options) 105: end
# File lib/spec/example/example_group_methods.rb, line 107 107: def set_description(*args) 108: @description_args, @options = args_and_options(*args) 109: @backtrace = caller(1) 110: @location = File.expand_path(options[:location]) if options[:location] 111: self 112: end
# File lib/spec/example/example_group_methods.rb, line 187 187: def dry_run(examples, run_options) 188: examples.each do |example| 189: run_options.reporter.example_started(example) 190: run_options.reporter.example_finished(example) 191: end 192: end
# File lib/spec/example/example_group_methods.rb, line 258 258: def example_method?(method_name) 259: should_method?(method_name) 260: end
# File lib/spec/example/example_group_methods.rb, line 233 233: def examples_to_run(run_options) 234: return example_proxies unless examples_were_specified?(run_options) 235: if run_options.line_number_requested? 236: if location =~ /:#{run_options.example_line}:?/ 237: example_proxies 238: else 239: example_proxies.select {|proxy| proxy.location =~ /:#{run_options.example_line}:?/} 240: end 241: else 242: example_proxies.reject do |proxy| 243: matcher = ExampleGroupMethods.matcher_class. 244: new(description.to_s, proxy.description) 245: !matcher.matches?(run_options.examples) 246: end 247: end 248: end
# File lib/spec/example/example_group_methods.rb, line 250 250: def examples_were_specified?(run_options) 251: !run_options.examples.empty? 252: end
# File lib/spec/example/example_group_methods.rb, line 221 221: def run_after_all(success, instance_variables, run_options) 222: return success if example_group_hierarchy.after_all_parts.empty? 223: example_proxy = ExampleProxy.new("after(:all)") 224: after_all = new(example_proxy) 225: after_all.set_instance_variables_from_hash(instance_variables) 226: example_group_hierarchy.run_after_all(after_all) 227: success 228: rescue Exception => e 229: run_options.reporter.example_failed(example_proxy, e) 230: false 231: end
# File lib/spec/example/example_group_methods.rb, line 194 194: def run_before_all(run_options) 195: return [true,{}] if example_group_hierarchy.before_all_parts.empty? 196: example_proxy = ExampleProxy.new("before(:all)") 197: before_all = new(example_proxy) 198: begin 199: example_group_hierarchy.run_before_all(before_all) 200: return [true, before_all.instance_variable_hash] 201: rescue Exception => e 202: run_options.reporter.example_failed(example_proxy, e) 203: return [false, before_all.instance_variable_hash] 204: end 205: end
# File lib/spec/example/example_group_methods.rb, line 207 207: def run_examples(success, instance_variables, examples, run_options) 208: return [success, instance_variables] unless success 209: 210: after_all_instance_variables = instance_variables 211: 212: examples.each do |example| 213: example_group_instance = new(example, &example_implementations[example]) 214: success &= example_group_instance.execute(run_options, instance_variables) 215: after_all_instance_variables = example_group_instance.instance_variable_hash 216: end 217: 218: return [success, after_all_instance_variables] 219: end
# File lib/spec/example/example_group_methods.rb, line 262 262: def should_method?(method_name) 263: !(method_name =~ /^should(_not)?$/) && 264: method_name =~ /^should/ && 265: instance_method(method_name).arity < 1 266: end
# File lib/spec/example/example_group_methods.rb, line 177 177: def subclass(*args, &example_group_block) 178: @class_count ||= 0 179: @class_count += 1 180: klass = const_set("Subclass_#{@class_count}", Class.new(self)) 181: klass.set_description(*args) 182: klass.include_constants_in(args.last[:scope]) 183: klass.module_eval(&example_group_block) 184: klass 185: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.