Sha256: 7416b77430f225af542d9c780fb63b05b4a319ccae6b0c67d458d510f9b4537c

Contents?: true

Size: 1.96 KB

Versions: 45

Compression:

Stored size: 1.96 KB

Contents

module Spec
  module Example
    class SharedExampleGroup < Module
      class << self
        def add_shared_example_group(new_example_group)
          guard_against_redefining_existing_example_group(new_example_group)
          shared_example_groups << new_example_group
        end

        def find_shared_example_group(example_group_description)
          shared_example_groups.find do |b|
            b.description == example_group_description
          end
        end

        def shared_example_groups
          # TODO - this needs to be global, or at least accessible from
          # from subclasses of Example in a centralized place. I'm not loving
          # this as a solution, but it works for now.
          $shared_example_groups ||= []
        end

        private
        def guard_against_redefining_existing_example_group(new_example_group)
          existing_example_group = find_shared_example_group(new_example_group.description)
          return unless existing_example_group
          return if new_example_group.equal?(existing_example_group)
          return if spec_path(new_example_group) == spec_path(existing_example_group)
          raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists")
        end

        def spec_path(example_group)
          File.expand_path(example_group.spec_path)
        end
      end
      include ExampleGroupMethods
      public :include

      def initialize(*args, &example_group_block)
        describe(*args)
        @example_group_block = example_group_block
        self.class.add_shared_example_group(self)
      end

      def included(mod) # :nodoc:
        mod.module_eval(&@example_group_block)
      end

      def execute_in_class_hierarchy(superclass_last=false)
        classes = [self]
        superclass_last ? classes << ExampleMethods : classes.unshift(ExampleMethods)
        classes.each do |example_group|
          yield example_group
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 7 rubygems

Version Path
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.0 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.1 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.3 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.4 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.2 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.6 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.5 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.7 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
picolena-0.1.8 rails_plugins/rspec/lib/spec/example/shared_example_group.rb
pictrails-0.5.0 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
radiant-0.6.5.1 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
radiant-0.6.5 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
radiant-0.6.6 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
radiant-0.6.7 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
radiant-0.6.8 vendor/plugins/rspec/lib/spec/example/shared_example_group.rb