# File lib/spec/example/example_group_methods.rb, line 8 def build_description_from(*args) text = args.inject("") do |description, arg| description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/) description << arg.to_s end text == "" ? nil : text 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 def describe(*args, &example_group_block) raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty? if example_group_block options = add_options(args) set_location(options, caller(0)[1]) if options[:shared] ExampleGroupFactory.create_shared_example_group(*args, &example_group_block) else subclass(*args, &example_group_block) end else set_description(*args) end end
# File lib/spec/example/example_group_methods.rb, line 126 def described_class @described_class ||= Class === described_type ? described_type : nil end
# File lib/spec/example/example_group_methods.rb, line 122 def described_type @described_type ||= description_parts.reverse.find {|part| part.is_a?(Module)} end
# File lib/spec/example/example_group_methods.rb, line 118 def description @description ||= ExampleGroupMethods.build_description_from(*description_parts) || to_s end
# File lib/spec/example/example_group_methods.rb, line 130 def description_args @description_args ||= [] 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 def example(description=nil, options={}, backtrace=nil, &implementation) example_proxy = ExampleProxy.new(description, options, backtrace || caller(0)[1]) example_proxies << example_proxy example_implementations[example_proxy] = implementation || pending_implementation example_proxy end
# File lib/spec/example/example_group_methods.rb, line 156 def example_group_hierarchy @example_group_hierarchy ||= ExampleGroupHierarchy.new(self) end
# File lib/spec/example/example_group_methods.rb, line 164 def include_constants_in(mod) include mod if (Spec::Ruby.version.to_f >= 1.9) & (Module === mod) & !(Class === mod) end
Use this to pull in examples from shared example groups.
# File lib/spec/example/example_group_methods.rb, line 64 def it_should_behave_like(*shared_example_groups) shared_example_groups.each do |group| include_shared_example_group(group) end end
# File lib/spec/example/example_group_methods.rb, line 168 def let(name, &block) define_method name do @assignments ||= {} @assignments[name] ||= instance_eval(&block) end end
# File lib/spec/example/example_group_methods.rb, line 160 def nested_descriptions example_group_hierarchy.nested_descriptions end
# File lib/spec/example/example_group_methods.rb, line 79 def pending_implementation lambda { raise(Spec::Example::NotYetImplementedError) } end
# File lib/spec/example/example_group_methods.rb, line 94 def run(run_options) examples = examples_to_run(run_options) notify(run_options.reporter) unless examples.empty? return true if examples.empty? return dry_run(examples, run_options) if run_options.dry_run? define_methods_from_predicate_matchers success, before_all_instance_variables = run_before_all(run_options) success, after_all_instance_variables = run_examples(success, before_all_instance_variables, examples, run_options) success = run_after_all(success, after_all_instance_variables, run_options) end
# File lib/spec/example/example_group_methods.rb, line 107 def set_description(*args) @description_args, @options = args_and_options(*args) @backtrace = caller(1) @location = File.expand_path(options[:location]) if options[:location] self end
Generated with the Darkfish Rdoc Generator 2.