lib/spec/example/example_group_methods.rb in dchelimsky-rspec-1.1.11 vs lib/spec/example/example_group_methods.rb in dchelimsky-rspec-1.1.11.1

- old
+ new

@@ -1,32 +1,50 @@ module Spec module Example module ExampleGroupMethods include Spec::Example::BeforeAndAfterHooks + + def self.matcher_class + @matcher_class + end + + def self.matcher_class=(matcher_class) + @matcher_class = matcher_class + end - class << self - attr_accessor :matcher_class - - def description_text(*args) - args.inject("") do |result, arg| - result << " " unless (result == "" || arg.to_s =~ /^(\s|\.|#)/) - result << arg.to_s - end + def self.description_text(*args) + args.inject("") do |result, arg| + result << " " unless (result == "" || arg.to_s =~ /^(\s|\.|#)/) + result << arg.to_s end end attr_reader :description_text, :description_options, :spec_path alias :options :description_options + # Provides the backtrace up to where this example_group was declared. + def backtrace + @backtrace + end + + # Deprecated - use +backtrace()+ + def example_group_backtrace + Kernel.warn <<-WARNING +ExampleGroupMethods#example_group_backtrace is deprecated and will be removed +from a future version. Please use ExampleGroupMethods#backtrace instead. +WARNING + backtrace + end + def description_args @description_args ||= [] end def inherited(klass) super - klass.register {} + klass.register Spec::Runner.register_at_exit_hook end # Makes the describe/it syntax available from a class. For example: # @@ -44,27 +62,28 @@ # def describe(*args, &example_group_block) args << {} unless Hash === args.last if example_group_block options = args.last - options[:spec_path] = eval("caller(0)[1]", example_group_block) unless options[:spec_path] + # Ruby 1.9 - the next line uses example_group_block.binding instead of example_group_block + options[:spec_path] = eval("caller(0)[1]", example_group_block.binding) unless options[:spec_path] if options[:shared] create_shared_example_group(*args, &example_group_block) else - create_nested_example_group(*args, &example_group_block) + create_subclass(*args, &example_group_block) end else set_description(*args) end end alias :context :describe - def create_shared_example_group(*args, &example_group_block) + def create_shared_example_group(*args, &example_group_block) # :nodoc: SharedExampleGroup.register(*args, &example_group_block) end - def create_nested_example_group(*args, &example_group_block) + def create_subclass(*args, &example_group_block) # :nodoc: self.subclass("Subclass") do set_description(*args) module_eval(&example_group_block) end end @@ -162,17 +181,17 @@ # it { should_not be_overdrawn} # end # # See +ExampleMethods#should+ for more information about this approach. def subject(&block) - if block - @_subject_block = block - else - @_subject_block.call if @_subject_block - end + @_subject_block = block end - + + def subject_block + @_subject_block || lambda {nil} + end + def description_parts #:nodoc: parts = [] each_ancestor_example_group_class do |example_group_class| parts << example_group_class.description_args end @@ -182,10 +201,11 @@ def set_description(*args) args, options = Spec::Example.args_and_options(*args) @description_args = args @description_options = options @description_text = ExampleGroupMethods.description_text(*args) + @backtrace = caller(1) @spec_path = File.expand_path(options[:spec_path]) if options[:spec_path] self end def examples #:nodoc: @@ -204,20 +224,15 @@ @after_all_parts = nil @before_each_parts = nil @after_each_parts = nil end - def register(&registration_binding_block) - @registration_binding_block = registration_binding_block + def register Spec::Runner.options.add_example_group self end def unregister #:nodoc: Spec::Runner.options.remove_example_group self - end - - def registration_backtrace - eval("caller", @registration_binding_block) end def run_before_each(example) each_ancestor_example_group_class do |example_group_class| example.eval_each_fail_fast(example_group_class.before_each_parts)