Sha256: d814b87de94fcbbc668dd4c9e2a4cdf816a8186a376f263790523384ea91c15f

Contents?: true

Size: 1.68 KB

Versions: 20

Compression:

Stored size: 1.68 KB

Contents

module Spec
  module Example
    class SharedExampleGroup < Module
      module ClassMethods
        def register(*args, &block)
          new_example_group = new(*args, &block)
          shared_example_groups << new_example_group unless already_registered?(new_example_group)
          new_example_group
        end
        
        def find(example_group_description)
          shared_example_groups.find {|b| b.description == example_group_description}
        end

        def clear
          shared_example_groups.clear
        end
        
        def include?(group)
          shared_example_groups.include?(group)
        end
        
        def count
          shared_example_groups.length
        end

      private
      
        def shared_example_groups
          @shared_example_groups ||= []
        end
      
        def already_registered?(new_example_group)
          existing_example_group = find(new_example_group.description)
          return false unless existing_example_group
          return true if new_example_group.equal?(existing_example_group)
          return true if expanded_path(new_example_group) == expanded_path(existing_example_group)
          raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists")
        end

        def expanded_path(example_group)
          File.expand_path(example_group.spec_path)
        end
      end

      extend ClassMethods
      include ExampleGroupMethods

      def initialize(*args, &example_group_block)
        set_description(*args)
        @example_group_block = example_group_block
      end

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

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.11.5 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.11.6 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.11.7 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.12 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.1 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.13 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.2 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.3 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.4 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.5 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.6 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.7 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.8 lib/spec/example/shared_example_group.rb
dchelimsky-rspec-1.1.99.9 lib/spec/example/shared_example_group.rb
newbamboo-evented-rspec-1.1.12 lib/spec/example/shared_example_group.rb
newbamboo-rspec-1.1.12 lib/spec/example/shared_example_group.rb
mack-0.8.3 lib/gems/rspec-1.1.12/lib/spec/example/shared_example_group.rb
mack-0.8.3.1 lib/gems/rspec-1.1.12/lib/spec/example/shared_example_group.rb
rspec-1.1.12 lib/spec/example/shared_example_group.rb
rspec-1.2.0 lib/spec/example/shared_example_group.rb