Sha256: 646646c5ad7c8358e570a3ee257155714eb9e12060cc41f7f828a0cf0fa86b25

Contents?: true

Size: 1.65 KB

Versions: 34

Compression:

Stored size: 1.65 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.location)
        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

34 entries across 34 versions & 11 rubygems

Version Path
rspec-instructure-1.3.3 lib/spec/example/shared_example_group.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/lib/spec/example/shared_example_group.rb
rspec-1.3.2 lib/spec/example/shared_example_group.rb
rspec-1.3.1 lib/spec/example/shared_example_group.rb
rspec-1.3.1.rc lib/spec/example/shared_example_group.rb
rspec-1.3.0 lib/spec/example/shared_example_group.rb
hubbub-0.0.11 lib/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
hubbub-0.0.10 lib/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
hubbub-0.0.9 lib/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
hubbub-0.0.8 lib/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
hubbub-0.0.6 lib/vendor/plugins/rspec/lib/spec/example/shared_example_group.rb
simple-templater-0.0.1.4 gems/gems/rspec-1.2.9/lib/spec/example/shared_example_group.rb
media-path-0.1.2 vendor/rspec/lib/spec/example/shared_example_group.rb
simple-templater-0.0.1.3 vendor/rspec/lib/spec/example/shared_example_group.rb
pupu-0.0.2.pre vendor/rspec/lib/spec/example/shared_example_group.rb
media-path-0.1.1.pre vendor/rspec/lib/spec/example/shared_example_group.rb
simple-templater-0.0.1.2 vendor/rspec/lib/spec/example/shared_example_group.rb
media-path-0.1.1 vendor/rspec/lib/spec/example/shared_example_group.rb
simple-templater-0.0.1.1 vendor/rspec/lib/spec/example/shared_example_group.rb
pupu-0.0.2 vendor/rspec/lib/spec/example/shared_example_group.rb